Conditions | 23 |
Paths | 21 |
Total Lines | 56 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
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 |
||
17 | public static function evaluate($value, string $rule, array $args): bool |
||
18 | { |
||
19 | switch($rule) { |
||
20 | case '=': |
||
21 | if((string)$value === (string)$args[0]) { |
||
22 | return true; |
||
23 | } |
||
24 | break; |
||
25 | case '!=': |
||
26 | if((string)$value !== (string)$args[0]) { |
||
27 | return true; |
||
28 | } |
||
29 | break; |
||
30 | case '>': |
||
31 | if($value > $args[0]) { |
||
32 | return true; |
||
33 | } |
||
34 | break; |
||
35 | case '>=': |
||
36 | if($value >= $args[0]) { |
||
37 | return true; |
||
38 | } |
||
39 | break; |
||
40 | case '<': |
||
41 | if($value < $args[0]) { |
||
42 | return true; |
||
43 | } |
||
44 | break; |
||
45 | case '<=': |
||
46 | if($value <= $args[0]) { |
||
47 | return true; |
||
48 | } |
||
49 | break; |
||
50 | case 'between': |
||
51 | if($value >= $args[0] && $value <= $args[1]) { |
||
52 | return true; |
||
53 | } |
||
54 | break; |
||
55 | case 'in': |
||
56 | if(in_array($value, $args[0])) { |
||
57 | return true; |
||
58 | } |
||
59 | break; |
||
60 | case 'not in': |
||
61 | if(!in_array($value, $args[0])) { |
||
62 | return true; |
||
63 | } |
||
64 | break; |
||
65 | case 'between strict': |
||
66 | if($value > $args[0] && $value < $args[1]) { |
||
67 | return true; |
||
68 | } |
||
69 | break; |
||
70 | } |
||
71 | |||
72 | return false; |
||
73 | } |
||
75 |