Conditions | 10 |
Paths | 9 |
Total Lines | 19 |
Code Lines | 13 |
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 |
||
16 | public static function mergeFields(&$original, $external, $overwrite) { |
||
17 | if ($original instanceof Map) { |
||
18 | foreach ($external as $key => $value) { |
||
|
|||
19 | if ($overwrite || !$original->has($key)) { |
||
20 | $original->set($key, $value); |
||
21 | } |
||
22 | } |
||
23 | } elseif ($original instanceof Set) { |
||
24 | foreach ($external as $value) { |
||
25 | $original->add($value); |
||
26 | } |
||
27 | } else { // if scalar |
||
28 | if ($overwrite) { |
||
29 | $original = null !== $external ? $external : $original; |
||
30 | } else { |
||
31 | $original = null === $original ? $external : $original; |
||
32 | } |
||
33 | } |
||
34 | } |
||
35 | } |
||
36 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.