Conditions | 5 |
Paths | 3 |
Total Lines | 25 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 5 |
Changes | 0 |
1 | <?php |
||
20 | 4 | public function run() |
|
21 | { |
||
22 | 4 | $model = new $this->modelClass; |
|
23 | |||
24 | 4 | if (($ids = Yii::$app->request->post('selection')) !== null) { |
|
25 | 4 | $models = $model::findAll($ids); |
|
26 | 4 | $operation = Yii::$app->request->post('operation'); |
|
27 | |||
28 | 4 | if (isset($this->operations[$operation])) { |
|
29 | 4 | $attrubutes = $this->operations[$operation]; |
|
30 | 4 | foreach ($models as $model) { |
|
31 | switch ($operation) { |
||
32 | 4 | case 'delete': |
|
33 | 2 | $model->delete(); |
|
34 | 2 | break; |
|
35 | default: |
||
36 | 2 | $model->updateAttributes($attrubutes); |
|
37 | 4 | break; |
|
38 | } |
||
39 | } |
||
40 | } |
||
41 | } |
||
42 | |||
43 | 4 | return $this->controller->asJson(true); |
|
|
|||
44 | } |
||
45 | } |
||
46 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: