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