Completed
Push — master ( d0bd4d...b4b0fd )
by Igor
23:04
created

RolesController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 73.91%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 6
dl 0
loc 70
c 0
b 0
f 0
ccs 17
cts 23
cp 0.7391
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A actions() 0 16 1
A actionIndex() 0 10 1
A behaviors() 0 12 1
B actionEdit() 0 24 5
1
<?php
2
3
namespace app\modules\admin\controllers;
4
5
use Yii;
6
use yii\filters\VerbFilter;
7
use app\traits\ModelTrait;
8
use app\models\entity\AuthItem;
9
use app\modules\admin\models\forms\AuthItemForm;
10
use app\modules\admin\models\search\AuthItemSearch;
11
12
class RolesController extends \yii\web\Controller
13
{
14
    use ModelTrait;
15
16 4
    public function behaviors()
17
    {
18
        return [
19 4
            'verbs' => [
20
                'class' => VerbFilter::class,
21
                'actions' => [
22
                    'delete' => ['post'],
23
                    'batch' => ['post'],
24
                ],
25
            ],
26
        ];
27
    }
28
29 4
    public function actions()
30
    {
31
        return [
32 4
            'batch' => [
33
                'class' => 'app\modules\admin\actions\BatchAction',
34
                'modelClass' => 'app\models\entity\AuthItem',
35
                'actions' => [
36
                    'delete' => [],
37
                ]
38
            ],
39
            'delete' => [
40
                'class' => 'app\modules\admin\actions\DeleteAction',
41
                'modelClass' => 'app\models\entity\AuthItem',
42
            ],
43
        ];
44
    }
45
46 4
    public function actionIndex()
47
    {
48 4
        $authItemSearch = new AuthItemSearch();
49 4
        $dataProvider = $authItemSearch->search(Yii::$app->request->get());
50
51 4
        return $this->render('index', [
52 4
            'authItemSearch' => $authItemSearch,
53 4
            'dataProvider' => $dataProvider,
54
        ]);
55
    }
56
57 3
    public function actionEdit($name = null)
58
    {
59 3
        $model = new AuthItemForm();
60
61 3
        if ($name) {
62 2
            $model->setModel($this->findModel(new AuthItem, $name));
0 ignored issues
show
Compatibility introduced by
$this->findModel(new \ap...tity\AuthItem(), $name) of type object<yii\db\ActiveRecord> is not a sub-type of object<app\models\entity\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...
63
        }
64
65 2
        if (Yii::$app->request->isPost) {
66
            Yii::$app->response->format = 'json';
67
68
            if ($model->load(Yii::$app->request->post()) && $model->validate()) {
69
                $model->save();
70
71
                Yii::$app->session->setFlash('success', Yii::t('app.msg', 'Saved successfully'));
72
                return $this->redirect(['edit', 'name' => $model->name]);
73
            }
74
            return $this->asJsonModelErrors($model);
75
        }
76
77 2
        return $this->render('edit', [
78 2
            'model' => $model,
79
        ]);
80
    }
81
}
82