RangeInitializer::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 14
ccs 7
cts 7
cp 1
rs 9.4285
cc 3
eloc 7
nc 3
nop 3
crap 3
1
<?php
2
3
namespace Underscore\Initializer;
4
5
use Underscore\Collection;
6
use Underscore\Initializer;
7
use Underscore\Underscore;
8
9
class RangeInitializer extends Initializer
10
{
11
    /**
12
     * Creates Underscore object containing array of numbers
13
     *
14
     * @param int $start Start number, inclusive
15
     * @param int $stop  Stop number, not inclusive
16
     * @param int $step  Step size, non-zero, can be negative
17
     *
18
     * @throws \LogicException
19
     * @return Underscore
20
     */
21 5
    public function __invoke($start, $stop, $step = 1)
22
    {
23 5
        if (0 == $step) {
24 1
            throw new \LogicException('$step have to be non-zero');
25
        }
26
27 4
        $array = [];
28
29 4
        for ($i = (int)$start; $i < (int)$stop; $i += (int)$step) {
30 3
            $array[] = $i;
31
        }
32
33 4
        return new Underscore(new Collection($array));
34
    }
35
}
36