| Conditions | 11 |
| Paths | 3 |
| Total Lines | 27 |
| Code Lines | 17 |
| 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 |
||
| 32 | public function mergeConfig(...$args): array |
||
| 33 | { |
||
| 34 | $res = array_shift($args) ?: []; |
||
| 35 | foreach ($args as $items) { |
||
| 36 | if (!is_array($items)) { |
||
| 37 | continue; |
||
| 38 | } |
||
| 39 | foreach ($items as $k => $v) { |
||
| 40 | if (is_int($k)) { |
||
| 41 | /// XXX skip repeated values |
||
| 42 | if (in_array($v, $res, true)) { |
||
| 43 | continue; |
||
| 44 | } |
||
| 45 | if (array_key_exists($k, $res)) { |
||
| 46 | $res[] = $v; |
||
| 47 | } else { |
||
| 48 | $res[$k] = $v; |
||
| 49 | } |
||
| 50 | } elseif (is_array($v) && isset($res[$k]) && is_array($res[$k])) { |
||
| 51 | $res[$k] = $this->mergeConfig($res[$k], $v); |
||
| 52 | } else { |
||
| 53 | $res[$k] = $v; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | return $res; |
||
| 59 | } |
||
| 93 |