| Conditions | 16 |
| Paths | 12 |
| Total Lines | 29 |
| Code Lines | 19 |
| 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 |
||
| 20 | public static function operateArray(array &$arr, $key, $value = null, $getDefault = null, \Closure $setAction = null, $override = false, $isSet = false) |
||
| 21 | { |
||
| 22 | if (($key === null || is_string($key) || is_int($key)) && $value === null && !$isSet) { |
||
| 23 | return $key === null ? $arr : |
||
| 24 | (isset($arr[$key]) ? $arr[$key] : $getDefault); |
||
| 25 | } |
||
| 26 | if (is_array($key) || is_object($key)) { |
||
| 27 | $index = 0; |
||
| 28 | if (empty($key) && $override) { |
||
| 29 | $arr = []; |
||
| 30 | } |
||
| 31 | foreach ($key as $k => $v) { |
||
| 32 | self::operateArray($arr, $k, $v, $getDefault, $setAction, ($override && !($index)), true); |
||
| 33 | $index++; |
||
| 34 | } |
||
| 35 | |||
| 36 | return $arr; |
||
| 37 | } |
||
| 38 | if ($override) { |
||
| 39 | $arr = []; |
||
| 40 | } |
||
| 41 | if (is_callable($setAction)) { |
||
| 42 | call_user_func_array($setAction, [$key, $value, $override]); |
||
| 43 | } else { |
||
| 44 | $arr[$key] = $value; |
||
| 45 | } |
||
| 46 | |||
| 47 | return $arr; |
||
| 48 | } |
||
| 49 | |||
| 69 |