GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Setup Failed
Push — filters ( 4f5140...7db5de )
by
unknown
12:50
created

BackendChunkController   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 125
Duplicated Lines 12 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 19
c 1
b 0
f 0
lcom 1
cbo 4
dl 15
loc 125
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A actions() 0 18 1
A behaviors() 0 14 1
A actionIndex() 0 17 1
D actionEdit() 0 40 9
A actionDelete() 15 15 4
A actionRemoveAll() 0 11 3

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 app\modules\core\controllers;
4
5
use app\backend\components\BackendController;
6
use app\backend\traits\BackendRedirect;
7
use app\modules\core\models\ContentBlockGroup;
8
use devgroup\JsTreeWidget\AdjacencyFullTreeDataAction;
9
use devgroup\JsTreeWidget\TreeNodeMoveAction;
10
use devgroup\JsTreeWidget\TreeNodesReorderAction;
11
use yii\filters\AccessControl;
12
use app\modules\core\models\ContentBlock;
13
use Yii;
14
use yii\helpers\Url;
15
use yii\web\NotFoundHttpException;
16
17
class BackendChunkController extends BackendController
18
{
19
    use BackendRedirect;
20
21
    public function actions()
22
    {
23
        return [
24
            'getTree' => [
25
                'class' => AdjacencyFullTreeDataAction::className(),
26
                'class_name' => ContentBlockGroup::className(),
27
                'model_label_attribute' => 'name',
28
            ],
29
            'move' => [
30
                'class' => TreeNodeMoveAction::className(),
31
                'className' => ContentBlockGroup::className(),
32
            ],
33
            'reorder' => [
34
                'class' => TreeNodesReorderAction::className(),
35
                'className' => ContentBlockGroup::className(),
36
            ],
37
        ];
38
    }
39
40
    public function behaviors()
41
    {
42
        return [
43
            'access' => [
44
                'class' => AccessControl::className(),
45
                'rules' => [
46
                    [
47
                        'allow' => true,
48
                        'roles' => ['content manage'],
49
                    ],
50
                ],
51
            ],
52
        ];
53
    }
54
55
    public function actionIndex()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Coding Style introduced by
actionIndex uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
56
    {
57
        $searchModel = new ContentBlock(['scenario' => 'search']);
58
        $group_id = Yii::$app->request->get('group_id', null);
59
        $searchModel->group_id = $group_id;
60
        $dataProvider = $searchModel->search($_GET);
61
62
63
        return $this->render(
64
            'index',
65
            [
66
                'dataProvider' => $dataProvider,
67
                'searchModel' => $searchModel,
68
                'parent_id' => $group_id
69
            ]
70
        );
71
    }
72
73
    public function actionEdit($id = null, $group_id = null)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
74
    {
75
        /** @var null|ContentBlock $model */
76
        $model = new ContentBlock();
77
        if ($id !== null) {
78
            $model = ContentBlock::findOne($id);
79
        }
80
81
        if ($model->isNewRecord === true && $group_id !== null) {
82
            $model->group_id = $group_id;
83
        }
84
        $model->loadDefaultValues();
85
86
87
        $post = \Yii::$app->request->post();
88
        if ($model->load($post) && $model->validate()) {
89
            if (!empty($model->newGroup)) {
90
                $group = new ContentBlockGroup([
91
                    'name' => $model->newGroup,
92
                ]);
93
                $group->loadDefaultValues();
94
                if ($group->save()) {
95
                    $model->group_id = $group->id;
96
                }
97
            }
98
            $save_result = $model->save();
99
            if ($save_result) {
100
                Yii::$app->session->setFlash('info', Yii::t('app', 'Object saved'));
101
                $this->redirectUser($model->id);
102
            } else {
103
                \Yii::$app->session->setFlash('error', Yii::t('app', 'Cannot update data'));
104
            }
105
        }
106
        return $this->render(
107
            'edit',
108
            [
109
                'model' => $model,
110
            ]
111
        );
112
    }
113
114 View Code Duplication
    public function actionDelete($id = null)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
115
    {
116
        if ((null === $id) || (null === $model = ContentBlock::findOne($id))) {
117
            throw new NotFoundHttpException;
118
        }
119
        if ($model->delete()) {
120
            Yii::$app->session->setFlash('info', Yii::t('app', 'Object removed'));
121
        }
122
        return $this->redirect(
123
            Yii::$app->request->get(
124
                'returnUrl',
125
                Url::toRoute(['index'])
126
            )
127
        );
128
    }
129
130
    public function actionRemoveAll()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
131
    {
132
        $items = Yii::$app->request->post('items', []);
133
        if (!empty($items)) {
134
            $items = ContentBlock::find()->where(['in', 'id', $items])->all();
135
            foreach ($items as $item) {
136
                $item->delete();
137
            }
138
        }
139
        return $this->redirect(['index']);
140
    }
141
}