| Conditions | 14 |
| Paths | 7 |
| Total Lines | 21 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 82 | protected function mixedGet($object, $key, $default = null) |
||
| 83 | { |
||
| 84 | if (is_null($key) || trim($key) == '') { |
||
| 85 | return ''; |
||
| 86 | } |
||
| 87 | foreach (explode('.', $key) as $segment) { |
||
| 88 | if (is_object($object) && isset($object->{$segment})) { |
||
| 89 | $object = $object->{$segment}; |
||
| 90 | } elseif (is_object($object) && method_exists($object, '__get') && ! is_null($object->__get($segment))) { |
||
| 91 | $object = $object->__get($segment); |
||
| 92 | } elseif (is_object($object) && method_exists($object, 'getAttribute') && ! is_null($object->getAttribute($segment))) { |
||
| 93 | $object = $object->getAttribute($segment); |
||
| 94 | } elseif (is_array($object) && array_key_exists($segment, $object)) { |
||
| 95 | $object = array_get($object, $segment, $default); |
||
| 96 | } else { |
||
| 97 | return value($default); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | return $object; |
||
| 102 | } |
||
| 103 | } |
||
| 104 |
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.