Passed
Pull Request — master (#18)
by
unknown
06:05
created

CountIterator   B

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 16

Test Coverage

Coverage 85%

Importance

Changes 0
Metric Value
dl 0
loc 70
ccs 17
cts 20
cp 0.85
rs 8.4614
c 0
b 0
f 0
wmc 7
lcom 1
cbo 16

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A rewind() 0 4 1
A current() 0 4 1
A key() 0 4 1
A next() 0 4 1
A valid() 0 4 1
A __debugInfo() 0 7 1
1
<?php
2
3
namespace Zicht\Itertools\lib;
4
5
use Zicht\Itertools\lib\Traits\AllTrait;
6
use Zicht\Itertools\lib\Traits\AnyTrait;
7
use Zicht\Itertools\lib\Traits\ChainTrait;
8
use Zicht\Itertools\lib\Traits\CycleTrait;
9
use Zicht\Itertools\lib\Traits\FilterTrait;
10
use Zicht\Itertools\lib\Traits\FirstTrait;
11
use Zicht\Itertools\lib\Traits\GroupByTrait;
12
use Zicht\Itertools\lib\Traits\LastTrait;
13
use Zicht\Itertools\lib\Traits\MapByTrait;
14
use Zicht\Itertools\lib\Traits\MapTrait;
15
use Zicht\Itertools\lib\Traits\ReduceTrait;
16
use Zicht\Itertools\lib\Traits\ReversedTrait;
17
use Zicht\Itertools\lib\Traits\SliceTrait;
18
use Zicht\Itertools\lib\Traits\SortedTrait;
19
use Zicht\Itertools\lib\Traits\UniqueTrait;
20
use Zicht\Itertools\lib\Traits\ZipTrait;
21
22
class CountIterator implements \Iterator
23
{
24
    // Fluent interface traits
25
    use AllTrait;
26
    use AnyTrait;
27
    use ChainTrait;
28
    use CycleTrait;
29
    use FilterTrait;
30
    use FirstTrait;
31
    use GroupByTrait;
32
    use LastTrait;
33
    use MapByTrait;
34
    use MapTrait;
35
    use ReduceTrait;
36
    use ReversedTrait;
37
    use SliceTrait;
38
    use SortedTrait;
39
    use UniqueTrait;
40
    use ZipTrait;
41
42
    protected $start;
43
    protected $step;
44
    protected $key;
45
46 30
    public function __construct($start, $step)
47
    {
48 30
        $this->start = $start;
49 30
        $this->step = $step;
50 30
        $this->key = 0;
51 30
    }
52
53 30
    public function rewind()
54
    {
55 30
        $this->key = 0;
56 30
    }
57
58 30
    public function current()
59
    {
60 30
        return $this->start + ($this->key * $this->step);
61
    }
62
63 30
    public function key()
64
    {
65 30
        return $this->key;
66
    }
67
68 30
    public function next()
69
    {
70 30
        $this->key += 1;
71 30
    }
72
73 30
    public function valid()
74
    {
75 30
        return true;
76
    }
77
78
    /**
79
     * This method is called by var_dump() when dumping an object to get the properties that should be shown.
80
     *
81
     * @link http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.debuginfo
82
     * @return array
83
     */
84
    public function __debugInfo()
85
    {
86
        return array_merge(
87
            ['__length__' => 'infinite'],
88
            iterator_to_array($this)
89
        );
90
    }
91
}
92