G   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 40
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A assertStep() 0 4 2
A __construct() 0 2 1
A range() 0 12 3
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