| Conditions | 13 |
| Paths | 13 |
| Total Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 74 | public static function compareByRule(string $rule, $value1, $value2) : bool |
||
| 75 | { |
||
| 76 | switch (static::tryRuleAliase($rule)) { |
||
| 77 | case '<=': |
||
| 78 | return ($value1 <= $value2); |
||
| 79 | case '>=': |
||
| 80 | return ($value1 >= $value2); |
||
| 81 | case '!like:': |
||
| 82 | return !StrHelper::like($value1, $value2); |
||
| 83 | case '!in:': |
||
| 84 | return !in_array($value1, $value2); |
||
| 85 | case '!contain:': |
||
| 86 | return !in_array($value2, $value1); |
||
| 87 | case 'like:': |
||
| 88 | return StrHelper::like($value1, $value2); |
||
| 89 | case 'contain:': |
||
| 90 | return in_array($value2, $value1); |
||
| 91 | case 'in:': |
||
| 92 | return in_array($value1, $value2); |
||
| 93 | case '<': |
||
| 94 | return ($value1 < $value2); |
||
| 95 | case '>': |
||
| 96 | return ($value1 > $value2); |
||
| 97 | case '!=': |
||
| 98 | return ($value1 != $value2); |
||
| 99 | case '=': |
||
| 100 | return ($value1 == $value2); |
||
| 101 | default: |
||
| 102 | throw new \UnexpectedValueException('Unknown rule '.$rule); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 121 |