| Conditions | 12 |
| Paths | 82 |
| Total Lines | 30 |
| Code Lines | 13 |
| 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 |
||
| 16 | public static function inRange( |
||
| 17 | null|float|int $value, |
||
| 18 | null|float|int $start = null, |
||
| 19 | null|float|int $end = null, |
||
| 20 | bool $startInclusive = true, |
||
| 21 | bool $endInclusive = false, |
||
| 22 | ): bool { |
||
| 23 | if (null === $value) { |
||
| 24 | return false; |
||
| 25 | } |
||
| 26 | |||
| 27 | if (null !== $start && null !== $end && (float) $start === (float) $end) { |
||
| 28 | return (float) $value === (float) $start; |
||
| 29 | } |
||
| 30 | |||
| 31 | if (null === $start) { |
||
| 32 | $startInclusive = true; |
||
| 33 | } |
||
| 34 | |||
| 35 | if (null === $end) { |
||
| 36 | $endInclusive = true; |
||
| 37 | } |
||
| 38 | |||
| 39 | // Depending on this->range[Start/End]Inclusive, we will use (>= or >) and (<= or <) to work out where the value is |
||
| 40 | $isGreater = $startInclusive ? $value >= $start : $value > $start; |
||
| 41 | $isLesser = $endInclusive ? $value <= $end : $value < $end; |
||
| 42 | |||
| 43 | return |
||
| 44 | (null === $start || $isGreater) |
||
| 45 | && (null === $end || $isLesser); |
||
| 46 | } |
||
| 57 |