Conditions | 6 |
Paths | 9 |
Total Lines | 28 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
23 | public function run($id, $name) |
||
24 | { |
||
25 | /** @var BaseActiveRecord $model */ |
||
26 | $model = $this->findModel($id); |
||
27 | |||
28 | if (!$model instanceof ResourceInterface) { |
||
29 | throw new BadRequestHttpException('Impossible to update relationships for resource'); |
||
30 | } |
||
31 | |||
32 | $data = \Yii::$app->getRequest()->getBodyParams(); |
||
|
|||
33 | $relationships = []; |
||
34 | foreach ($data as $modelName => $identifier) { |
||
35 | if (!isset($identifier['id'])) { |
||
36 | continue; |
||
37 | } |
||
38 | /** @var BaseActiveRecord $modelName */ |
||
39 | if ($relationship = $modelName::findOne($identifier['id'])) { |
||
40 | $relationships[] = $relationship; |
||
41 | } |
||
42 | } |
||
43 | |||
44 | if (!empty($relationships)) { |
||
45 | $model->unlinkAll($name); |
||
46 | $model->setResourceRelationship($name, $relationships); |
||
47 | } |
||
48 | |||
49 | throw new ServerErrorHttpException('Failed to update the relationship for unknown reason.'); |
||
50 | } |
||
51 | } |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.