RangeInitializer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 0
cbo 3
dl 0
loc 27
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 14 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