Completed
Push — master ( 85769a...b67e6b )
by Igor
07:14
created

RolesController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 77.27%

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 1
cbo 7
dl 0
loc 68
ccs 17
cts 22
cp 0.7727
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A behaviors() 0 12 1
A actions() 0 16 1
A actionIndex() 0 10 1
B actionEdit() 0 22 5
1
<?php
2
3
namespace app\modules\admin\controllers;
4
5
use Yii;
6
use yii\filters\VerbFilter;
7
use yii\helpers\Url;
8
use app\traits\ModelTrait;
9
use app\models\AuthItem;
10
use app\modules\admin\models\forms\AuthItemForm;
11
use app\modules\admin\models\search\AuthItemSearch;
12
13
class RolesController extends \yii\web\Controller
14
{
15
    use ModelTrait;
16
17 4
    public function behaviors()
18
    {
19
        return [
20 4
            'verbs' => [
21
                'class' => VerbFilter::class,
22
                'actions' => [
23
                    'delete' => ['post'],
24
                    'operations' => ['post'],
25
                ],
26
            ],
27
        ];
28
    }
29
30 4
    public function actions()
31
    {
32
        return [
33 4
            'operations' => [
34
                'class' => 'app\modules\admin\controllers\common\OperationsAction',
35
                'modelClass' => 'app\models\AuthItem',
36
                'operations' => [
37
                    'delete' => [],
38
                ]
39
            ],
40
            'delete' => [
41
                'class' => 'app\modules\admin\controllers\common\DeleteAction',
42
                'modelClass' => 'app\models\AuthItem',
43
            ],
44
        ];
45
    }
46
47 4
    public function actionIndex()
48
    {
49 4
        $authItemSearch = new AuthItemSearch();
50 4
        $dataProvider = $authItemSearch->search(Yii::$app->request->get());
51
52 4
        return $this->render('index', [
53 4
            'authItemSearch' => $authItemSearch,
54 4
            'dataProvider' => $dataProvider,
55
        ]);
56
    }
57
58 3
    public function actionEdit($name = null)
59
    {
60 3
        $model = new AuthItemForm();
61
62 3
        if ($name) {
63 2
            $model->setModel($this->findModel(new AuthItem, $name));
0 ignored issues
show
Compatibility introduced by
$this->findModel(new \ap...dels\AuthItem(), $name) of type object<yii\db\ActiveRecord> is not a sub-type of object<app\models\AuthItem>. It seems like you assume a child class of the class yii\db\ActiveRecord to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
64
        }
65
66 2
        if (Yii::$app->request->isPost) {
67
            if ($model->load(Yii::$app->request->post()) && $model->validate()) {
68
                $model->save();
69
70
                Yii::$app->session->setFlash('success', Yii::t('app.msg', 'Saved successfully'));
71
                return $this->asJson(['redirect' => Url::toRoute(['edit', 'name' => $model->name])]);
72
            }
73
            return $this->asJson($this->collectErrors($model));
74
        }
75
76 2
        return $this->render('edit', [
77 2
            'model' => $model,
78
        ]);
79
    }
80
}
81