| Conditions | 16 |
| Paths | 23 |
| Total Lines | 43 |
| Code Lines | 29 |
| 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 |
||
| 106 | private static function mergeArrays(array &$dataOrigin, array $data, array $saveKeys = []) |
||
| 107 | { |
||
| 108 | foreach ($data as $key => $value) { |
||
| 109 | if (!isset($dataOrigin[$key])) { |
||
| 110 | $dataOrigin[$key] = null; |
||
| 111 | } |
||
| 112 | |||
| 113 | $mergeable = !in_array($key, $saveKeys); |
||
| 114 | $operation = isset($saveKeys[$key]); |
||
| 115 | |||
| 116 | switch (true) { |
||
| 117 | case is_numeric($value) && $mergeable && !$operation: |
||
| 118 | $dataOrigin[$key] += $value; |
||
| 119 | break; |
||
| 120 | |||
| 121 | case is_array($value) && $mergeable && !$operation: |
||
| 122 | if (null === $dataOrigin[$key]) { |
||
| 123 | $dataOrigin[$key] = []; |
||
| 124 | } |
||
| 125 | self::mergeArrays($dataOrigin[$key], $value); |
||
| 126 | break; |
||
| 127 | |||
| 128 | case $mergeable && $operation: |
||
| 129 | if (null === $dataOrigin[$key]) { |
||
| 130 | $dataOrigin[$key] = []; |
||
| 131 | } elseif (!is_array($dataOrigin[$key])) { |
||
| 132 | $dataOrigin[$key] = array($dataOrigin[$key]); |
||
| 133 | } |
||
| 134 | if (is_array($value)) { |
||
| 135 | $dataOrigin[$key] = array_merge($dataOrigin[$key], $value); |
||
| 136 | } else { |
||
| 137 | $dataOrigin[$key][] = $value; |
||
| 138 | } |
||
| 139 | break; |
||
| 140 | |||
| 141 | default: |
||
| 142 | if (null === $dataOrigin[$key]) { |
||
| 143 | $dataOrigin[$key] = $value; |
||
| 144 | } |
||
| 145 | break; |
||
| 146 | } |
||
| 147 | } |
||
| 148 | } |
||
| 149 | } |