| Conditions | 14 |
| Paths | 7 |
| Total Lines | 28 |
| Code Lines | 18 |
| Lines | 8 |
| Ratio | 28.57 % |
| 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 |
||
| 91 | protected function mixedGet($object, $key, $default = null) |
||
| 92 | { |
||
| 93 | if (is_null($key) || trim($key) == '') { |
||
| 94 | return ''; |
||
| 95 | } |
||
| 96 | foreach (explode('.', $key) as $segment) { |
||
| 97 | if (is_object($object) && isset($object->{$segment})) { |
||
| 98 | $object = $object->{$segment}; |
||
| 99 | continue; |
||
| 100 | } |
||
| 101 | View Code Duplication | if (is_object($object) && method_exists($object, '__get') && ! is_null($object->__get($segment))) { |
|
| 102 | $object = $object->__get($segment); |
||
| 103 | continue; |
||
| 104 | } |
||
| 105 | View Code Duplication | if (is_object($object) && method_exists($object, 'getAttribute') && ! is_null($object->getAttribute($segment))) { |
|
| 106 | $object = $object->getAttribute($segment); |
||
| 107 | continue; |
||
| 108 | } |
||
| 109 | if (is_array($object) && array_key_exists($segment, $object)) { |
||
| 110 | $object = array_get($object, $segment, $default); |
||
| 111 | continue; |
||
| 112 | } |
||
| 113 | |||
| 114 | return value($default); |
||
| 115 | } |
||
| 116 | |||
| 117 | return $object; |
||
| 118 | } |
||
| 119 | } |
||
| 120 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.