| Conditions | 10 |
| Paths | 6 |
| Total Lines | 22 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 101 | private static function normalizeValue(ReflectionParameter $param, $value) |
||
| 102 | { |
||
| 103 | if (null === $value) { |
||
| 104 | return $value; |
||
| 105 | } |
||
| 106 | |||
| 107 | if (null !== ($class = $param->getClass()) && false === is_object($value)) { |
||
| 108 | if (is_scalar($value) && $class->hasMethod('fromString')) { |
||
| 109 | return $class->getMethod('fromString')->invoke(null, $value); |
||
| 110 | } |
||
| 111 | |||
| 112 | if ((is_array($value) || is_object($value)) && $class->hasMethod('deserialize')) { |
||
| 113 | return $class->getMethod('deserialize')->invoke(null, $value); |
||
| 114 | } |
||
| 115 | |||
| 116 | if ($class->isInstantiable()) { |
||
| 117 | return $class->newInstance($value); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | return $value; |
||
| 122 | } |
||
| 123 | } |
||
| 124 |