Conditions | 17 |
Paths | 14 |
Total Lines | 30 |
Code Lines | 24 |
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 |
||
38 | public static function getValue(array $haystack = null, $key = null, $sub = null, $default = null) |
||
39 | { |
||
40 | if (empty($key) && !isset($haystack)) { |
||
41 | return $default; |
||
42 | } elseif (empty($key)) { |
||
43 | if (!isset($haystack) && null !== $default) { |
||
44 | return $default; |
||
45 | } elseif (isset($haystack)) { |
||
46 | return $haystack; |
||
47 | } |
||
48 | return null; |
||
49 | } elseif (!empty($key) && empty($sub)) { |
||
50 | if (empty($haystack[$key]) && null !== $default) { |
||
51 | return $default; |
||
52 | } elseif (isset($haystack[$key])) { |
||
53 | return $haystack[$key]; |
||
54 | } |
||
55 | return null; |
||
56 | } elseif (is_array($sub)) { |
||
57 | $array = isset($haystack[$key]) ? $haystack[$key] : []; |
||
58 | $value = self::findInMultiArray($sub, $array); |
||
59 | if (empty($value) && null !== $default) { |
||
60 | return $default; |
||
61 | } elseif (isset($value)) { |
||
62 | return $value; |
||
63 | } |
||
64 | return null; |
||
65 | } |
||
66 | return null; |
||
67 | } |
||
68 | |||
88 |