Conditions | 7 |
Paths | 6 |
Total Lines | 24 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 7.0283 |
Changes | 0 |
1 | <?php |
||
64 | 2 | private function fixValue(string $value) |
|
65 | { |
||
66 | 2 | if ('' === $value) { |
|
67 | 1 | return null; |
|
68 | } |
||
69 | |||
70 | 2 | if ('true' === $value) { |
|
71 | 1 | return true; |
|
72 | } |
||
73 | |||
74 | 2 | if ('false' === $value) { |
|
75 | return false; |
||
76 | } |
||
77 | |||
78 | 2 | if (is_numeric($value) && '0' !== $value[0]) { |
|
79 | 2 | if ((string) (int) $value === $value) { |
|
80 | 2 | return (int) $value; |
|
81 | } |
||
82 | |||
83 | 2 | return (float) $value; |
|
84 | } |
||
85 | |||
86 | 2 | return $value; |
|
87 | } |
||
88 | } |
||
89 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.