LanguageController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 54
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getModelName() 0 3 1
A actionSetDefault() 0 11 3
A getSearchModelName() 0 3 1
A init() 0 7 1
1
<?php
2
3
namespace Itstructure\AdminModule\controllers;
4
5
use yii\web\NotFoundHttpException;
6
use Itstructure\AdminModule\models\{Language, LanguageSearch};
7
8
/**
9
 * Class LanguageController
10
 * LanguageController implements the CRUD actions for Language model.
11
 *
12
 * @package Itstructure\AdminModule\controllers
13
 *
14
 * @author Andrey Girnik <[email protected]>
15
 */
16
class LanguageController extends CommonAdminController
17
{
18
    /**
19
     * Initialize.
20
     */
21
    public function init()
22
    {
23
        $this->viewPath = '@admin/views/language';
24
25
        $this->setEditingScenarios = true;
26
27
        parent::init();
28
    }
29
30
    /**
31
     * Set language as default.
32
     *
33
     * @param $languageId
34
     *
35
     * @return \yii\web\Response
36
     *
37
     * @throws NotFoundHttpException
38
     */
39
    public function actionSetDefault($languageId)
40
    {
41
        $language = Language::findOne($languageId);
42
        if (null === $language) {
43
            throw  new NotFoundHttpException('Language with id ' . $languageId . ' does not exist');
44
        }
45
46
        $language->default = $language->default == 0 ? 1 : 0;
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $language->default of type mixed|null to 0; this is ambiguous as not only 0 == 0 is true, but null == 0 is true, too. Consider using a strict comparison ===.
Loading history...
47
        $language->save();
48
49
        return $this->redirect('index');
50
    }
51
52
    /**
53
     * Returns Language model name.
54
     *
55
     * @return string
56
     */
57
    protected function getModelName():string
58
    {
59
        return Language::class;
60
    }
61
62
    /**
63
     * Returns LanguageSearch model name.
64
     *
65
     * @return string
66
     */
67
    protected function getSearchModelName():string
68
    {
69
        return LanguageSearch::class;
70
    }
71
}
72