G::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace AlecRabbit\Accessories;
4
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
42
    {
43 24
        if ($step <= 0) {
44 4
            throw new \LogicException('Step has to be greater than zero');
45
        }
46 20
    }
47
}
48