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