| Conditions | 12 |
| Paths | 39 |
| Total Lines | 31 |
| Code Lines | 16 |
| 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 |
||
| 104 | private function array_merge_recursive_distinct() { |
||
| 105 | |||
| 106 | $arrays = func_get_args(); |
||
| 107 | $base = array_shift($arrays); |
||
| 108 | |||
| 109 | if(!is_array($base)) $base = empty($base) ? array() : array($base); |
||
| 110 | |||
| 111 | foreach($arrays as $append) { |
||
| 112 | |||
| 113 | if(!is_array($append)) $append = array($append); |
||
| 114 | |||
| 115 | foreach($append as $key => $value) { |
||
| 116 | |||
| 117 | if(!array_key_exists($key, $base) and !is_numeric($key)) { |
||
| 118 | $base[$key] = $append[$key]; |
||
| 119 | continue; |
||
| 120 | } |
||
| 121 | |||
| 122 | if(is_array($value) or is_array($base[$key])) { |
||
| 123 | $base[$key] = $this->array_merge_recursive_distinct($base[$key], $append[$key]); |
||
| 124 | } else if(is_numeric($key)) { |
||
| 125 | if(!in_array($value, $base)) $base[] = $value; |
||
| 126 | } else { |
||
| 127 | $base[$key] = $value; |
||
| 128 | } |
||
| 129 | |||
| 130 | } |
||
| 131 | |||
| 132 | } |
||
| 133 | |||
| 134 | return $base; |
||
| 135 | } |
||
| 136 | } |