IndexController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 1
cbo 4
dl 0
loc 67
ccs 15
cts 15
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A behaviors() 0 37 1
A actionIndex() 0 8 2
A actionLogin() 0 11 3
A actionLogout() 0 5 1
1
<?php
2
3
namespace app\modules\admin\controllers;
4
5
use Yii;
6
use yii\web\ForbiddenHttpException;
7
use app\modules\admin\models\forms\LoginForm;
8
9
/**
10
 * Allowed controller for all
11
 */
12
class IndexController extends \yii\web\Controller
13 14
{
14
    public function behaviors()
15
    {
16 14
        return [
17
            'access' => [
18
                'class' => 'yii\filters\AccessControl',
19
                'rules' => [
20
                    [
21
                        'allow'   => true,
22
                        'actions' => ['index'],
23
                        'roles'   => ['@', 'AdminModule'],
24
                    ],
25
                    [
26
                        'allow'   => true,
27
                        'actions' => ['login'],
28
                        'roles'   => ['?'],
29
                    ],
30
                    [
31
                        'allow'   => true,
32
                        'actions' => ['logout'],
33
                        'roles'   => ['@'],
34
                    ],
35
                    [
36
                        'allow'   => true,
37
                        'actions' => ['error'],
38
                        'roles'   => ['*'],
39
                    ],
40
                    // everything else is denied
41
                ],
42
            ],
43
            'verbs' => [
44
                'class' => 'yii\filters\VerbFilter',
45
                'actions' => [
46
                    'logout' => ['post'],
47
                ],
48
            ],
49
        ];
50
    }
51 3
52
    public function actionIndex()
53 3
    {
54 1
        if (!Yii::$app->user->can('AdminModule')) {
55
            throw new ForbiddenHttpException(Yii::t('app', 'Access Denied'));
56
        }
57 2
58
        return $this->render('index');
59
    }
60 14
61
    public function actionLogin()
62 14
    {
63
        $model = new LoginForm();
64 14
65 2
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
66
            return $this->goBack();
67 14
        }
68 14
        return $this->render('login', [
69
            'model' => $model,
70
        ]);
71
    }
72 1
73
    public function actionLogout()
74 1
    {
75 1
        Yii::$app->user->logout();
76
        return $this->goHome();
77
    }
78
}
79