| Conditions | 10 |
| Paths | 3 |
| Total Lines | 33 |
| Code Lines | 20 |
| 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 |
||
| 52 | private static function mergeBase(...$args): ArrayCollection |
||
| 53 | { |
||
| 54 | $collection = new ArrayCollection(); |
||
| 55 | |||
| 56 | while (!empty($args)) { |
||
| 57 | $array = array_shift($args); |
||
| 58 | |||
| 59 | if ($array instanceof ArrayCollection) { |
||
| 60 | $collection->pullCollectionArgs($array); |
||
| 61 | $collection->setData( |
||
| 62 | static::mergeBase($collection->getData(), $array->getData())->getData() |
||
| 63 | ); |
||
| 64 | continue; |
||
| 65 | } |
||
| 66 | |||
| 67 | foreach ($array as $k => $v) { |
||
| 68 | if (is_int($k)) { |
||
| 69 | if ($collection->keyExists($k)) { |
||
| 70 | if ($collection[$k] !== $v) { |
||
| 71 | $collection[] = $v; |
||
| 72 | } |
||
| 73 | } else { |
||
| 74 | $collection[$k] = $v; |
||
| 75 | } |
||
| 76 | } elseif (static::isMergable($v) && isset($collection[$k]) && static::isMergable($collection[$k])) { |
||
| 77 | $collection[$k] = static::mergeBase($collection[$k], $v)->getData(); |
||
| 78 | } else { |
||
| 79 | $collection[$k] = $v; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | return $collection; |
||
| 85 | } |
||
| 96 |