| Conditions | 11 |
| Paths | 7 |
| Total Lines | 33 |
| 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 |
||
| 55 | public function merge(array $array1, array $arrays = null) |
||
| 56 | { |
||
| 57 | $arrays = array_slice(func_get_args(), 1); |
||
| 58 | if (count($arrays) === 0) { |
||
| 59 | return $array1; |
||
| 60 | } |
||
| 61 | |||
| 62 | // if all arrays are sequential and flag is set, append them all |
||
| 63 | if ($this->flags & static::FLAG_APPEND_VALUE_ARRAY == static::FLAG_APPEND_VALUE_ARRAY |
||
| 64 | && $this->areSequential(array_merge([$array1], $arrays))) { |
||
| 65 | return call_user_func_array('array_merge', array_merge([$array1], $arrays)); |
||
| 66 | } |
||
| 67 | |||
| 68 | $merged = $array1; |
||
| 69 | |||
| 70 | foreach ($arrays as $toMerge) { |
||
| 71 | foreach ($toMerge as $key => &$value) { |
||
| 72 | if (array_key_exists($key, $merged)) { |
||
| 73 | if ($this->flags & static::FLAG_APPEND_VALUE_ARRAY == static::FLAG_APPEND_VALUE_ARRAY |
||
| 74 | && is_array($value) |
||
| 75 | && is_array($merged[$key]) |
||
| 76 | && $this->areSequential([$value, $merged[$key]])) { |
||
| 77 | $merged[$key] = array_merge($merged[$key], $value); |
||
| 78 | } else { |
||
| 79 | $merged[$key] = call_user_func($this->valueMerger, $merged[$key], $value); |
||
| 80 | } |
||
| 81 | } else { |
||
| 82 | $merged[$key] = $value; |
||
| 83 | } |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | return $merged; |
||
| 88 | } |
||
| 90 |