| Conditions | 10 |
| Paths | 32 |
| Total Lines | 23 |
| 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 |
||
| 84 | protected static function evaluateOperation($left, string $operator, $right) |
||
| 85 | { |
||
| 86 | if (!is_numeric($left)) { |
||
| 87 | $left = 0; |
||
| 88 | } |
||
| 89 | if (!is_numeric($right)) { |
||
| 90 | $right = 0; |
||
| 91 | } |
||
| 92 | if ($operator === '%') { |
||
| 93 | return $left % $right; |
||
| 94 | } elseif ($operator === '-') { |
||
| 95 | return $left - $right; |
||
| 96 | } elseif ($operator === '+') { |
||
| 97 | return $left + $right; |
||
| 98 | } elseif ($operator === '*') { |
||
| 99 | return $left * $right; |
||
| 100 | } elseif ($operator === '/') { |
||
| 101 | return (integer) $right !== 0 ? $left / $right : 0; |
||
| 102 | } elseif ($operator === '^') { |
||
| 103 | return pow($left, $right); |
||
| 104 | } |
||
| 105 | return 0; |
||
| 106 | } |
||
| 107 | } |
||
| 108 |