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