SiteController::actionLogout()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
namespace backend\controllers;
3
4
use Yii;
5
use yii\filters\AccessControl;
6
use yii\web\Controller;
7
use common\models\LoginForm;
8
use yii\filters\VerbFilter;
9
10
/**
11
 * Site controller
12
 */
13
class SiteController extends Controller
14
{
15
    /**
16
     * @inheritdoc
17
     */
18
    public function behaviors()
19
    {
20
        return [
21
            'access' => [
22
                'class' => AccessControl::className(),
23
                'rules' => [
24
                    [
25
                        'actions' => ['login', 'error'],
26
                        'allow' => true,
27
                    ],
28
                    [
29
                        'actions' => ['logout', 'index'],
30
                        'allow' => true,
31
                        'roles' => ['@'],
32
                    ],
33
                ],
34
            ],
35
            'verbs' => [
36
                'class' => VerbFilter::className(),
37
                'actions' => [
38
                    'logout' => ['post'],
39
                ],
40
            ],
41
        ];
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47
    public function actions()
48
    {
49
        return [
50
            'error' => [
51
                'class' => 'yii\web\ErrorAction',
52
            ],
53
        ];
54
    }
55
56
    public function actionIndex()
57
    {
58
        return $this->render('index');
59
    }
60
61 View Code Duplication
    public function actionLogin()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
    {
63
        if (!\Yii::$app->user->isGuest) {
64
            return $this->goHome();
65
        }
66
67
        $model = new LoginForm();
68
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
69
            return $this->goBack();
70
        } else {
71
            return $this->render('login', [
72
                'model' => $model,
73
            ]);
74
        }
75
    }
76
77
    public function actionLogout()
78
    {
79
        Yii::$app->user->logout();
80
81
        return $this->goHome();
82
    }
83
}
84