Conditions | 4 |
Paths | 4 |
Total Lines | 14 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 4 |
Changes | 0 |
1 | <?php |
||
20 | 20 | public static function range(int $start, int $stop, int $step = 1): \Generator |
|
21 | { |
||
22 | 20 | if ($step <= 0) { |
|
23 | 4 | throw new \LogicException('Step has to be greater than zero'); |
|
24 | } |
||
25 | 16 | $i = $start; |
|
26 | 16 | $direction = $stop <=> $start; |
|
27 | 16 | $step = $direction * $step; |
|
28 | 16 | $halt = false; |
|
29 | 16 | while (!$halt) { |
|
30 | 16 | yield $i; |
|
31 | 16 | $i += $step; |
|
32 | 16 | if ((($i - $stop) <=> 0) === $direction) { |
|
33 | 16 | $halt = true; |
|
34 | } |
||
50 |