Conditions | 14 |
Paths | 7 |
Total Lines | 21 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 1 |
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 |
||
21 | function notifynder_mixed_get($object, $key, $default = null) |
||
22 | { |
||
23 | if (is_null($key) || trim($key) == '') { |
||
24 | return ''; |
||
25 | } |
||
26 | foreach (explode('.', $key) as $segment) { |
||
27 | if (is_object($object) && isset($object->{$segment})) { |
||
28 | $object = $object->{$segment}; |
||
29 | } elseif (is_object($object) && method_exists($object, '__get') && ! is_null($object->__get($segment))) { |
||
30 | $object = $object->__get($segment); |
||
31 | } elseif (is_object($object) && method_exists($object, 'getAttribute') && ! is_null($object->getAttribute($segment))) { |
||
32 | $object = $object->getAttribute($segment); |
||
33 | } elseif (is_array($object) && array_key_exists($segment, $object)) { |
||
34 | $object = array_get($object, $segment, $default); |
||
35 | } else { |
||
36 | return value($default); |
||
37 | } |
||
38 | } |
||
39 | |||
40 | return $object; |
||
41 | } |
||
42 | } |
||
43 |