This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace app\controllers; |
||
4 | |||
5 | use Yii; |
||
6 | use app\models\Screen; |
||
7 | use app\models\ScreenTemplate; |
||
8 | use app\models\Flow; |
||
9 | use yii\helpers\ArrayHelper; |
||
10 | use yii\data\ActiveDataProvider; |
||
11 | use yii\filters\VerbFilter; |
||
12 | use yii\filters\AccessControl; |
||
13 | use yii\web\NotFoundHttpException; |
||
14 | |||
15 | /** |
||
16 | * ScreenController implements the CRUD actions for Screen model. |
||
17 | */ |
||
18 | class ScreenController extends BaseController |
||
19 | { |
||
20 | /** |
||
21 | * {@inheritdoc} |
||
22 | */ |
||
23 | View Code Duplication | public function behaviors() |
|
0 ignored issues
–
show
|
|||
24 | { |
||
25 | return [ |
||
26 | 'verbs' => [ |
||
27 | 'class' => VerbFilter::class, |
||
28 | 'actions' => [ |
||
29 | 'delete' => ['POST'], |
||
30 | ], |
||
31 | ], |
||
32 | 'access' => [ |
||
33 | 'class' => AccessControl::class, |
||
34 | 'only' => ['index', 'view', 'create', 'update', 'delete', 'link', 'unlink'], |
||
35 | 'rules' => [ |
||
36 | ['allow' => true, 'actions' => ['index', 'view', 'create', 'update', 'delete', 'link', 'unlink'], 'roles' => ['setScreens']], |
||
37 | ], |
||
38 | ], |
||
39 | ]; |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Lists all Screen models. |
||
44 | * |
||
45 | * @return string |
||
46 | */ |
||
47 | public function actionIndex() |
||
48 | { |
||
49 | $dataProvider = new ActiveDataProvider([ |
||
50 | 'query' => Screen::find()->joinWith('template'), |
||
51 | ]); |
||
52 | |||
53 | $dataProvider->sort->attributes['template'] = [ |
||
54 | 'asc' => [ScreenTemplate::tableName() . '.name' => SORT_ASC], |
||
55 | 'desc' => [ScreenTemplate::tableName() . '.name' => SORT_DESC], |
||
56 | ]; |
||
57 | |||
58 | return $this->render('index', [ |
||
59 | 'dataProvider' => $dataProvider, |
||
60 | ]); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * Displays a single Screen model. |
||
65 | * |
||
66 | * @param int $id |
||
67 | * |
||
68 | * @return string |
||
69 | */ |
||
70 | public function actionView($id) |
||
71 | { |
||
72 | $model = Screen::find()->where([Screen::tableName() . '.id' => $id])->joinWith('template')->one(); |
||
73 | if ($model === null) { |
||
74 | throw new NotFoundHttpException(Yii::t('app', 'The requested screen does not exist.')); |
||
75 | } |
||
76 | |||
77 | $dataProvider = new ActiveDataProvider([ |
||
78 | 'query' => $model->getFlows(), |
||
79 | ]); |
||
80 | |||
81 | return $this->render('view', [ |
||
82 | 'model' => $model, |
||
83 | 'dataProvider' => $dataProvider, |
||
84 | ]); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * Creates a new Screen model. |
||
89 | * If creation is successful, the browser will be redirected to the 'view' page. |
||
90 | * |
||
91 | * @return \yii\web\Response|string redirect or render |
||
92 | */ |
||
93 | public function actionCreate($device_id = null) |
||
94 | { |
||
95 | $model = new Screen(); |
||
96 | $model->loadDefaultValues(); |
||
97 | |||
98 | if ($model->load(Yii::$app->request->post()) && $model->save()) { |
||
99 | if ($device_id !== null) { |
||
100 | return $this->redirect(['device/link', 'id' => $device_id]); |
||
101 | } |
||
102 | |||
103 | return $this->redirect(['view', 'id' => $model->id]); |
||
104 | View Code Duplication | } else { |
|
0 ignored issues
–
show
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. ![]() |
|||
105 | $templates = ScreenTemplate::find()->all(); |
||
106 | $templatesArray = array_reduce($templates, function ($a, $t) { |
||
107 | $a[$t->id] = $t->name; |
||
108 | |||
109 | return $a; |
||
110 | }, []); |
||
111 | |||
112 | return $this->render('create', [ |
||
113 | 'model' => $model, |
||
114 | 'templates' => $templatesArray, |
||
115 | ]); |
||
116 | } |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * Updates an existing Screen model. |
||
121 | * If update is successful, the browser will be redirected to the 'view' page. |
||
122 | * |
||
123 | * @param int $id |
||
124 | * |
||
125 | * @return \yii\web\Response|string redirect or render |
||
126 | */ |
||
127 | public function actionUpdate($id) |
||
128 | { |
||
129 | $model = $this->findModel($id); |
||
130 | |||
131 | if ($model->load(Yii::$app->request->post()) && $model->save()) { |
||
132 | return $this->redirect(['view', 'id' => $model->id]); |
||
133 | View Code Duplication | } else { |
|
0 ignored issues
–
show
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. ![]() |
|||
134 | $templates = ScreenTemplate::find()->all(); |
||
135 | $templatesArray = array_reduce($templates, function ($a, $t) { |
||
136 | $a[$t->id] = $t->name; |
||
137 | |||
138 | return $a; |
||
139 | }, []); |
||
140 | |||
141 | return $this->render('update', [ |
||
142 | 'model' => $model, |
||
143 | 'templates' => $templatesArray, |
||
144 | ]); |
||
145 | } |
||
146 | } |
||
147 | |||
148 | /** |
||
149 | * Deletes an existing Screen model. |
||
150 | * If deletion is successful, the browser will be redirected to the 'index' page. |
||
151 | * |
||
152 | * @param int $id |
||
153 | * |
||
154 | * @return \yii\web\Response |
||
155 | */ |
||
156 | public function actionDelete($id) |
||
157 | { |
||
158 | $this->findModel($id)->delete(); |
||
159 | |||
160 | return $this->redirect(['index']); |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * Adds a flow to this screen or render link view. |
||
165 | * |
||
166 | * @param int $id |
||
167 | * @param int $flowId |
||
168 | * |
||
169 | * @return \yii\web\Response|string redirect or render |
||
170 | */ |
||
171 | View Code Duplication | public function actionLink($id, $flowId = null) |
|
172 | { |
||
173 | $model = $this->findModel($id); |
||
174 | |||
175 | if ($flowId === null) { |
||
176 | $dataProvider = new ActiveDataProvider([ |
||
177 | 'query' => Flow::find()->where(['not', ['id' => ArrayHelper::getColumn($model->flows, 'id')]]), |
||
178 | ]); |
||
179 | |||
180 | return $this->render('link', [ |
||
181 | 'model' => $model, |
||
182 | 'dataProvider' => $dataProvider, |
||
183 | ]); |
||
184 | } else { |
||
185 | if (!$model->getFlows()->where(['id' => $flowId])->exists() && ($flow = Flow::findOne($flowId)) !== null) { |
||
186 | $model->link('flows', $flow); |
||
0 ignored issues
–
show
It seems like
$flow defined by \app\models\Flow::findOne($flowId) on line 185 can also be of type array ; however, yii\db\BaseActiveRecord::link() does only seem to accept object<yii\db\ActiveRecordInterface> , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() |
|||
187 | } |
||
188 | |||
189 | return $this->redirect(['view', 'id' => $id]); |
||
190 | } |
||
191 | } |
||
192 | |||
193 | /** |
||
194 | * Remove a flow from a screen. |
||
195 | * |
||
196 | * @param int $id |
||
197 | * @param int $flowId |
||
198 | * |
||
199 | * @return \yii\web\Response |
||
200 | */ |
||
201 | View Code Duplication | public function actionUnlink($id, $flowId) |
|
0 ignored issues
–
show
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. ![]() |
|||
202 | { |
||
203 | $model = $this->findModel($id); |
||
204 | |||
205 | if ($model->getFlows()->where(['id' => $flowId])->exists() && ($flow = Flow::findOne($flowId)) !== null) { |
||
206 | $model->unlink('flows', $flow, true); |
||
0 ignored issues
–
show
It seems like
$flow defined by \app\models\Flow::findOne($flowId) on line 205 can also be of type array ; however, yii\db\BaseActiveRecord::unlink() does only seem to accept object<yii\db\ActiveRecordInterface> , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() |
|||
207 | } |
||
208 | |||
209 | return $this->redirect(['view', 'id' => $id]); |
||
210 | } |
||
211 | |||
212 | /** |
||
213 | * Finds the Screen model based on its primary key value. |
||
214 | * If the model is not found, a 404 HTTP exception will be thrown. |
||
215 | * |
||
216 | * @param int $id |
||
217 | * |
||
218 | * @return Screen the loaded model |
||
219 | * |
||
220 | * @throws NotFoundHttpException if the model cannot be found |
||
221 | */ |
||
222 | View Code Duplication | protected function findModel($id) |
|
223 | { |
||
224 | if (($model = Screen::findOne($id)) !== null) { |
||
0 ignored issues
–
show
|
|||
225 | return $model; |
||
226 | } else { |
||
227 | throw new NotFoundHttpException(Yii::t('app', 'The requested screen does not exist.')); |
||
228 | } |
||
229 | } |
||
230 | } |
||
231 |
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.