| Conditions | 11 |
| Paths | 8 |
| Total Lines | 32 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 16.3179 |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 7 | 1 | public static function makeBoolean($value): bool |
|
| 8 | { |
||
| 9 | 1 | $value = strtolower($value); |
|
| 10 | |||
| 11 | 1 | if ($value === true || $value === false) { |
|
| 12 | return $value; |
||
|
|
|||
| 13 | } |
||
| 14 | |||
| 15 | 1 | if ($value === 'true') { |
|
| 16 | 1 | return true; |
|
| 17 | } |
||
| 18 | |||
| 19 | 1 | if ($value === 'false') { |
|
| 20 | 1 | return false; |
|
| 21 | } |
||
| 22 | |||
| 23 | 1 | if ($value === 1 || $value === '1') { |
|
| 24 | 1 | return true; |
|
| 25 | } |
||
| 26 | |||
| 27 | 1 | if ($value === 0 || $value === '0') { |
|
| 28 | 1 | return false; |
|
| 29 | } |
||
| 30 | |||
| 31 | if (is_array($value)) { |
||
| 32 | return !empty($value); |
||
| 33 | } |
||
| 34 | |||
| 35 | if (trim($value) !== '') { |
||
| 36 | return true; |
||
| 37 | } else { |
||
| 38 | return false; |
||
| 39 | } |
||
| 42 |