Conditions | 10 |
Paths | 16 |
Total Lines | 34 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
31 | protected function linkRelationships($model, array $data = []) |
||
32 | { |
||
33 | if ($this->linkRelationships !== null) { |
||
34 | call_user_func($this->linkRelationships, $this, $model, $data); |
||
35 | return; |
||
36 | } |
||
37 | |||
38 | if (!$model instanceof ResourceInterface) { |
||
39 | return; |
||
40 | } |
||
41 | |||
42 | foreach ($data as $name => $relationship) { |
||
43 | if (!$related = $model->getRelation($name, false)) { |
||
|
|||
44 | continue; |
||
45 | } |
||
46 | /** @var BaseActiveRecord $relatedClass */ |
||
47 | $relatedClass = new $related->modelClass; |
||
48 | $relationships = ArrayHelper::keyExists($relatedClass->formName(), $relationship) ? $relationship[$relatedClass->formName()] : []; |
||
49 | |||
50 | $ids = []; |
||
51 | foreach ($relationships as $index => $relObject) { |
||
52 | if (!isset($relObject['id'])) { |
||
53 | continue; |
||
54 | } |
||
55 | $ids[] = $relObject['id']; |
||
56 | } |
||
57 | |||
58 | if ($related->multiple && !$this->allowFullReplacement) { |
||
59 | continue; |
||
60 | } |
||
61 | $records = $relatedClass::find()->andWhere(['in', $relatedClass::primaryKey(), $ids])->all(); |
||
62 | $model->setResourceRelationship($name, $records); |
||
63 | } |
||
64 | } |
||
65 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.