We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 11 |
Paths | 11 |
Total Lines | 24 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 13.8217 |
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 |
||
95 | 8 | public function syncPivot($model, $data, $form = 'create') |
|
96 | { |
||
97 | 8 | $fields_with_relationships = $this->getRelationFields($form); |
|
98 | |||
99 | 8 | foreach ($fields_with_relationships as $key => $field) { |
|
100 | 4 | if (isset($field['pivot']) && $field['pivot']) { |
|
101 | 3 | $values = isset($data[$field['name']]) ? $data[$field['name']] : []; |
|
102 | 3 | $model->{$field['name']}()->sync($values); |
|
103 | |||
104 | 2 | if (isset($field['pivotFields'])) { |
|
105 | foreach ($field['pivotFields'] as $pivotField) { |
||
106 | foreach ($data[$pivotField] as $pivot_id => $pivot_field) { |
||
107 | $model->{$field['name']}()->updateExistingPivot($pivot_id, [$pivotField => $pivot_field]); |
||
108 | } |
||
109 | } |
||
110 | } |
||
111 | } |
||
112 | |||
113 | 3 | if (isset($field['morph']) && $field['morph'] && isset($data[$field['name']])) { |
|
114 | $values = $data[$field['name']]; |
||
115 | 3 | $model->{$field['name']}()->sync($values); |
|
116 | } |
||
117 | } |
||
118 | 7 | } |
|
119 | } |
||
120 |
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.