| Conditions | 10 |
| Paths | 5 |
| Total Lines | 20 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 10.0751 |
| Changes | 1 | ||
| Bugs | 1 | Features | 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 |
||
| 20 | 6 | private function processCasting(Attribute $attribute, $value) |
|
| 21 | { |
||
| 22 | 6 | if ($attribute->isNullable() && $value === null) { |
|
| 23 | 1 | return $value; |
|
| 24 | } |
||
| 25 | |||
| 26 | 5 | if (($castFunction = $attribute->getCast()) !== null && is_callable($castFunction)) { |
|
| 27 | 2 | return $castFunction($value); |
|
| 28 | } |
||
| 29 | |||
| 30 | 5 | if ((($type = $attribute->getCast()) !== null && is_string($type)) || |
|
| 31 | 5 | (is_string($type = $attribute->cast(null)) && in_array(strtolower($type), ['bool', 'boolean', 'string', 'double', 'float', 'int', 'integer', 'array', 'object']))) { |
|
| 32 | 3 | return $this->castFromString($type, $value); |
|
| 33 | } |
||
| 34 | |||
| 35 | 2 | if (! ($attribute->cast(null) instanceof Attribute)) { |
|
| 36 | return $attribute->cast($value); |
||
| 37 | } |
||
| 38 | |||
| 39 | 2 | return $value; |
|
| 40 | } |
||
| 66 |