Conditions | 10 |
Paths | 8 |
Total Lines | 26 |
Code Lines | 15 |
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 |
||
11 | function array_merge_recursive_distinct(...$arrays) |
||
12 | { |
||
13 | if (count($arrays) < 2) { |
||
14 | return empty($arrays) ? [] : $arrays[0]; |
||
15 | } |
||
16 | |||
17 | $merged = array_shift($arrays); |
||
18 | |||
19 | foreach ($arrays as $array) { |
||
20 | foreach ($array as $key => $value) { |
||
21 | if (is_array($value) && (isset($merged[$key]) && is_array($merged[$key]))) { |
||
22 | $merged[$key] = array_merge_recursive_distinct($merged[$key], $value); |
||
23 | } else { |
||
24 | if (is_numeric($key)) { |
||
25 | if (! in_array($value, $merged)) { |
||
26 | $merged[] = $value; |
||
27 | } |
||
28 | } else { |
||
29 | $merged[$key] = $value; |
||
30 | } |
||
31 | } |
||
32 | } |
||
33 | unset($key, $value); |
||
34 | } |
||
35 | |||
36 | return $merged; |
||
37 | } |
||
38 |