| Conditions | 10 |
| Paths | 10 |
| Total Lines | 21 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 13.1494 |
| 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 |
||
| 42 | 3 | private function castFromString(string $type, $value) |
|
| 43 | { |
||
| 44 | 3 | switch (strtolower($type)) { |
|
| 45 | 3 | case 'boolean': |
|
| 46 | 3 | case 'bool': |
|
| 47 | 1 | return (bool) $value; |
|
| 48 | 2 | case 'string': |
|
| 49 | 1 | return (string) $value; |
|
| 50 | 1 | case 'double': |
|
| 51 | return (float) $value; |
||
| 52 | 1 | case 'integer': |
|
| 53 | 1 | case 'int': |
|
| 54 | return (int) $value; |
||
| 55 | 1 | case 'float': |
|
| 56 | return (float) $value; |
||
| 57 | 1 | case 'array': |
|
| 58 | 1 | return (array) $value; |
|
| 59 | case 'object': |
||
| 60 | return (object) $value; |
||
| 61 | default: |
||
| 62 | throw new \RuntimeException('cast type not supported'); |
||
| 63 | } |
||
| 66 |