| Conditions | 12 |
| Paths | 4 |
| Total Lines | 35 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 72 | private static function mergeWithKeysAsReverseMerge(...$args): ArrayCollection |
||
| 73 | { |
||
| 74 | $collection = new ArrayCollection(); |
||
| 75 | |||
| 76 | while (!empty($args)) { |
||
| 77 | $array = array_pop($args); |
||
| 78 | |||
| 79 | if ($array instanceof ArrayCollection) { |
||
| 80 | $collection->pullCollectionArgs($array); |
||
| 81 | $collection->setData( |
||
| 82 | static::mergeWithKeysAsReverseMerge($collection->getData(), $array->getData())->getData() |
||
| 83 | ); |
||
| 84 | continue; |
||
| 85 | } elseif (!is_array($array)) { |
||
| 86 | throw new InvalidArgumentException(); |
||
| 87 | } |
||
| 88 | |||
| 89 | foreach ($array as $k => $v) { |
||
| 90 | if (is_int($k)) { |
||
| 91 | if ($collection->keyExists($k)) { |
||
| 92 | if ($collection[$k] !== $v) { |
||
| 93 | $collection[] = $v; |
||
| 94 | } |
||
| 95 | } else { |
||
| 96 | $collection[$k] = $v; |
||
| 97 | } |
||
| 98 | } elseif (static::isMergable($v) && isset($collection[$k]) && static::isMergable($collection[$k])) { |
||
| 99 | $collection[$k] = static::mergeWithKeysAsReverseMerge($v, $collection[$k]); |
||
| 100 | } elseif (!$collection->keyExists($k)) { |
||
| 101 | $collection[$k] = $v; |
||
| 102 | } |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | return $collection; |
||
| 107 | } |
||
| 114 |