| Total Complexity | 6 |
| Total Lines | 40 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | class G |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Static class. Private Constructor. |
||
| 9 | */ |
||
| 10 | // @codeCoverageIgnoreStart |
||
| 11 | protected function __construct() |
||
| 12 | { |
||
| 13 | } |
||
| 14 | // @codeCoverageIgnoreEnd |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @param int $start |
||
| 18 | * @param int $stop |
||
| 19 | * @param int|float $step |
||
| 20 | * @return \Generator |
||
| 21 | */ |
||
| 22 | 24 | public static function range(int $start, int $stop, $step = 1): \Generator |
|
| 23 | { |
||
| 24 | 24 | static::assertStep($step); |
|
| 25 | 20 | $i = $start; |
|
| 26 | 20 | $direction = $stop <=> $start; |
|
| 27 | 20 | $step = $direction * $step; |
|
| 28 | 20 | $halt = false; |
|
| 29 | 20 | while (!$halt) { |
|
| 30 | 20 | yield $i; |
|
| 31 | 20 | $i += $step; |
|
| 32 | 20 | if ((($i - $stop) <=> 0) === $direction) { |
|
| 33 | 20 | $halt = true; |
|
| 34 | } |
||
| 35 | } |
||
| 36 | 20 | } |
|
| 37 | |||
| 38 | /** |
||
| 39 | * @param int|float $step |
||
| 40 | */ |
||
| 41 | 24 | protected static function assertStep($step): void |
|
| 45 | } |
||
| 46 | 20 | } |
|
| 47 | } |
||
| 48 |