| Conditions | 13 |
| Paths | 4 |
| Total Lines | 16 |
| Code Lines | 10 |
| 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 |
||
| 71 | public function getColor(int $percent = null): string |
||
| 72 | { |
||
| 73 | $pal = $this->palette; |
||
| 74 | if ($percent === null) { |
||
| 75 | return $this->bgColor ?? ''; |
||
| 76 | } |
||
| 77 | foreach ($pal as $i => $iValue) { |
||
| 78 | if (($i === 0 && $percent < $iValue[0]) |
||
| 79 | || ($i > 0 && $iValue[0] === $pal[$i - 1][0] && $percent === $iValue[0]) |
||
| 80 | || ($i > 0 && $iValue[0] !== $pal[$i - 1][0] && $percent < $iValue[0]) |
||
| 81 | || ($i === (count($pal) - 1) && $percent > $iValue[0]) |
||
| 82 | ) { |
||
| 83 | return $iValue[1]; |
||
| 84 | } |
||
| 85 | } |
||
| 86 | throw new LogicException("The percentage $percent did not match any range in the color palette."); |
||
| 87 | } |
||
| 90 |