We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 12 |
Paths | 26 |
Total Lines | 28 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
75 | public function syncPivot($model, $data, $form = 'create') |
||
76 | { |
||
77 | $fields_with_relationships = $this->getRelationFields($form); |
||
78 | |||
79 | foreach ($fields_with_relationships as $key => $field) { |
||
80 | if (isset($field['pivot']) && $field['pivot']) { |
||
81 | $values = isset($data[$field['name']]) ? $data[$field['name']] : []; |
||
82 | $model->{$field['name']}()->sync($values); |
||
83 | |||
84 | if (isset($field['pivotFields'])) { |
||
85 | foreach ($field['pivotFields'] as $pivotField) { |
||
86 | foreach ($data[$pivotField] as $pivot_id => $field) { |
||
87 | $model->{$field['name']}()->updateExistingPivot($pivot_id, [$pivotField => $field]); |
||
88 | } |
||
89 | } |
||
90 | } |
||
91 | } |
||
92 | |||
93 | if (isset($field['morph']) && $field['morph']) { |
||
94 | $values = isset($data[$field['name']]) ? $data[$field['name']] : []; |
||
95 | if($model->{$field['name']}) { |
||
96 | $model->{$field['name']}()->update($values); |
||
97 | } else { |
||
98 | $model->{$field['name']}()->create($values); |
||
99 | } |
||
100 | } |
||
101 | } |
||
102 | } |
||
103 | } |
||
104 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.