Conditions | 13 |
Paths | 3 |
Total Lines | 41 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
22 | public static function mergeConfig(array ...$arrays): array |
||
23 | { |
||
24 | $result = array_shift($arrays) ?: []; |
||
25 | foreach ($arrays as $items) { |
||
26 | if (!is_array($items)) { |
||
27 | continue; |
||
28 | } |
||
29 | foreach ($items as $key => $value) { |
||
30 | if ($value instanceof UnsetArrayValue) { |
||
31 | unset($result[$key]); |
||
32 | continue; |
||
33 | } |
||
34 | |||
35 | if ($value instanceof ReplaceArrayValue) { |
||
36 | $result[$key] = $value->value; |
||
37 | continue; |
||
38 | } |
||
39 | |||
40 | if (is_int($key)) { |
||
41 | /// XXX skip repeated values |
||
42 | if (in_array($value, $result, true)) { |
||
43 | continue; |
||
44 | } |
||
45 | |||
46 | if (array_key_exists($key, $result)) { |
||
47 | $result[] = $value; |
||
48 | } |
||
49 | |||
50 | continue; |
||
51 | } |
||
52 | |||
53 | if (is_array($value) && array_key_exists($key, $result) && is_array($result[$key])) { |
||
54 | $result[$key] = self::mergeConfig($result[$key], $value); |
||
55 | continue; |
||
56 | } |
||
57 | |||
58 | $result[$key] = $value; |
||
59 | } |
||
60 | } |
||
61 | |||
62 | return $result; |
||
63 | } |
||
65 |