SiteController   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 83
Duplicated Lines 25.3 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 21
loc 83
ccs 0
cts 54
cp 0
rs 10
c 0
b 0
f 0
wmc 12
lcom 0
cbo 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A behaviors() 21 21 1
A actions() 0 9 1
A actionLogin() 0 5 2
A actionLogout() 0 4 1
A actionRequestpasswordreset() 0 5 3
A actionResetpassword() 0 10 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace zacksleo\yii2\backend\tests\controllers;
4
5
use yii;
6
use yii\base\InvalidParamException;
7
use yii\web\BadRequestHttpException;
8
use yii\web\Controller;
9
use yii\filters\AccessControl;
10
use zacksleo\yii2\backend\models\forms\LoginForm;
11
use zacksleo\yii2\backend\models\forms\PasswordResetRequestForm;
12
use zacksleo\yii2\backend\models\forms\ResetPasswordForm;
13
14
/**
15
 * Default controller for the `backend` module
16
 */
17
class SiteController extends Controller
18
{
19
    public $layout = '@vendor/zacksleo/yii2-backend/src/views/layouts/layout';
20
    public $_viewPath = '@vendor/zacksleo/yii2-backend/src/views/site/';
21
22 View Code Duplication
    public function behaviors()
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...
23
    {
24
        return [
25
            'access' => [
26
                'class' => AccessControl::className(),
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
27
                'only' => ['login', 'logout', 'index'],
28
                'rules' => [
29
                    [
30
                        'allow' => true,
31
                        'actions' => ['login'],
32
                        'roles' => ['?'],
33
                    ],
34
                    [
35
                        'allow' => true,
36
                        'actions' => ['index', 'logout'],
37
                        'roles' => ['@'],
38
                    ]
39
                ],
40
            ]
41
        ];
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47
    public function actions()
48
    {
49
        return [
50
            'error' => [
51
                'class' => 'yii\web\ErrorAction',
52
                'view' => '@vendor/zacksleo/yii2-backend/src/views/site/error'
53
            ],
54
        ];
55
    }
56
57
    public function actionLogin()
58
    {
59
        $model = new LoginForm();
60
        return $model->load(Yii::$app->request->post()) && $model->login();
61
    }
62
63
    /**
64
     * User logout
65
     */
66
    public function actionLogout()
67
    {
68
        return Yii::$app->user->logout();
69
    }
70
71
    /**
72
     * Requests password reset.
73
     *
74
     * @return mixed
75
     */
76
    public function actionRequestpasswordreset()
77
    {
78
        $model = new PasswordResetRequestForm();
79
        return $model->load(Yii::$app->request->bodyParams) && $model->validate() && $model->sendEmail();
80
    }
81
82
    /**
83
     * Resets password.
84
     *
85
     * @param string $token
86
     * @return mixed
87
     * @throws BadRequestHttpException
88
     */
89
    public function actionResetpassword($token)
90
    {
91
        try {
92
            $model = new ResetPasswordForm($token);
93
        } catch (InvalidParamException $e) {
94
            throw new BadRequestHttpException($e->getMessage());
95
        }
96
        $model->load(Yii::$app->request->bodyParams);
97
        return $model->load(Yii::$app->request->bodyParams) && $model->validate() && $model->resetPassword();
98
    }
99
}
100