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 ( 8094dd...b8aa76 )
by
unknown
17:27
created

WysiwygController::actionCreate()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 12
rs 9.4286
c 1
b 0
f 0
cc 3
eloc 7
nc 2
nop 0
1
<?php
2
3
namespace app\modules\core\backend;
4
5
use app\backend\components\BackendController;
6
use app\modules\core\models\Wysiwyg;
7
use yii\filters\AccessControl;
8
use yii\filters\VerbFilter;
9
use Yii;
10
use yii\web\NotFoundHttpException;
11
12
class WysiwygController extends BackendController
13
{
14
    public function behaviors()
15
    {
16
        return [
17
            'access' => [
18
                'class' => AccessControl::className(),
19
                'rules' => [
20
                    [
21
                        'allow' => true,
22
                        'roles' => ['administrate'],
23
                    ],
24
                ],
25
            ],
26
            'verbs' => [
27
                'class' => VerbFilter::className(),
28
                'actions' => [
29
                    'delete' => ['POST'],
30
                ],
31
            ],
32
        ];
33
    }
34
35
36
    /**
37
     * Lists all Wysiwyg models.
38
     * @return mixed
39
     */
40 View Code Duplication
    public function actionIndex()
1 ignored issue
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...
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...
41
    {
42
        $searchModel = new Wysiwyg(['scenario' => 'search']);
43
        $dataProvider = $searchModel->search($_GET);
44
45
        return $this->render('index', [
46
            'dataProvider' => $dataProvider,
47
            'searchModel' => $searchModel
48
        ]);
49
    }
50
51
    /**
52
     * Displays a single Wysiwyg model.
53
     * @param integer $id
54
     * @return mixed
55
     */
56
    public function actionView($id)
57
    {
58
        return $this->render('view', [
59
            'model' => $this->findModel($id),
60
        ]);
61
    }
62
63
    /**
64
     * Creates a new Wysiwyg model.
65
     * If creation is successful, the browser will be redirected to the 'view' page.
66
     * @return mixed
67
     */
68
    public function actionCreate()
69
    {
70
        $model = new Wysiwyg();
71
72
        if ($model->load(\Yii::$app->request->post()) && $model->save()) {
73
            return $this->redirect(['view', 'id' => $model->id]);
74
        } else {
75
            return $this->render('create', [
76
                'model' => $model,
77
            ]);
78
        }
79
    }
80
81
    /**
82
     * Updates an existing Wysiwyg model.
83
     * If update is successful, the browser will be redirected to the 'view' page.
84
     * @param integer $id
85
     * @return mixed
86
     */
87
    public function actionUpdate($id, $returnUrl = null)
88
    {
89
        $model = $this->findModel($id);
90
91 View Code Duplication
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
92
            if ($returnUrl !== null) {
93
                return $this->redirect($returnUrl);
94
            }
95
            return $this->redirect(['view', 'id' => $model->id]);
96
        } else {
97
            return $this->render('update', [
98
                'model' => $model,
99
            ]);
100
        }
101
    }
102
103
    /**
104
     * Deletes an existing Wysiwyg model.
105
     * If deletion is successful, the browser will be redirected to the 'index' page.
106
     * @param integer $id
107
     * @return mixed
108
     */
109
    public function actionDelete($id)
110
    {
111
        $this->findModel($id)->delete();
112
113
        return $this->redirect(['index']);
114
    }
115
116
    /**
117
     * Finds the Wysiwyg model based on its primary key value.
118
     * If the model is not found, a 404 HTTP exception will be thrown.
119
     * @param integer $id
120
     * @return Wysiwyg the loaded model
121
     * @throws NotFoundHttpException if the model cannot be found
122
     */
123
    protected function findModel($id)
124
    {
125
        if (($model = Wysiwyg::findOne($id)) !== null) {
126
            return $model;
127
        } else {
128
            throw new NotFoundHttpException('The requested page does not exist.');
129
        }
130
    }
131
}
132