Conditions | 11 |
Paths | 16 |
Total Lines | 35 |
Code Lines | 20 |
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 |
||
45 | public static function strictMerge($a, $b) |
||
46 | { |
||
47 | $args = func_get_args(); |
||
48 | $res = array_shift($args); |
||
49 | while (!empty($args)) { |
||
50 | foreach (array_shift($args) as $k => $v) { |
||
51 | if ($v instanceof UnsetArrayValue) { |
||
52 | unset($res[$k]); |
||
53 | } elseif ($v instanceof ReplaceArrayValue) { |
||
54 | $res[$k] = $v->value; |
||
55 | } elseif (is_int($k)) { |
||
56 | if (array_key_exists($k, $res)) { |
||
57 | $res[] = $v; |
||
58 | } else { |
||
59 | $res[$k] = $v; |
||
60 | } |
||
61 | } elseif (is_array($v) && isset($res[$k]) && is_array($res[$k])) { |
||
62 | $res[$k] = self::merge($res[$k], $v); |
||
63 | } else { |
||
64 | $res[$k] = $v; |
||
65 | } |
||
66 | } |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * If this is a sequential 0-based indexed array, strip out any non-unique |
||
71 | * array values |
||
72 | * |
||
73 | * aaw -- 2018.03.18 |
||
74 | */ |
||
75 | if (array_keys($res) === range(0, count($res) - 1)) { |
||
76 | $res = array_values(array_unique($res)); |
||
77 | } |
||
78 | |||
79 | return $res; |
||
80 | } |
||
129 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.