Conditions | 11 |
Paths | 3 |
Total Lines | 21 |
Code Lines | 12 |
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 |
||
106 | public static function searchMd($multidimensional, $target, $isObject = true) |
||
107 | { |
||
108 | if (empty($target) || empty($multidimensional)) { |
||
109 | return false; |
||
110 | } |
||
111 | |||
112 | $output = array_map( |
||
113 | function($element) use ($target, $isObject) { |
||
114 | $exist = true; |
||
115 | foreach ($target as $skey => $svalue) { |
||
116 | $exist = $isObject |
||
117 | ? ($exist && isset($element->$skey) && ($element->$skey === $svalue)) |
||
118 | : ($exist && isset($element[$skey]) && ($element[$skey] === $svalue)); |
||
119 | } |
||
120 | return $exist ? $element : null; |
||
121 | }, |
||
122 | $multidimensional |
||
123 | ); |
||
124 | |||
125 | // If output is not empty, false by default |
||
126 | return !empty($output) ? array_filter($output) : false; |
||
127 | } |
||
130 |