Passed
Push — master ( 9e9b54...8c04f5 )
by
unknown
38s
created

CountIterator   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 85
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 1

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 12 3
1
<?php
2
/**
3
 * @author Boudewijn Schoon <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
7
namespace Zicht\Itertools\lib;
8
9
use Zicht\Itertools\lib\Interfaces\InfiniteIterableInterface;
10
use Zicht\Itertools\lib\Traits\InfiniteIterableTrait;
11
12
/**
13
 * Class CountIterator
14
 *
15
 * @package Zicht\Itertools\lib
16
 */
17
class CountIterator implements InfiniteIterableInterface
18
{
19
    use InfiniteIterableTrait;
20
21
    /** @var integer */
22
    protected $start;
23
24
    /** @var integer */
25
    protected $step;
26
27
    /** @var integer */
28
    protected $key;
29
30
    /**
31
     * CountIterator constructor.
32
     *
33
     * @param integer $start
34
     * @param integer $step
35
     */
36 31
    public function __construct($start, $step)
37
    {
38 31
        $this->start = $start;
39 31
        $this->step = $step;
40 31
        $this->key = 0;
41 31
    }
42
43
    /**
44
     * @{inheritDoc}
45
     */
46 31
    public function rewind()
47
    {
48 31
        $this->key = 0;
49 31
    }
50
51
    /**
52
     * @{inheritDoc}
53
     */
54 31
    public function current()
55
    {
56 31
        return $this->start + ($this->key * $this->step);
57
    }
58
59
    /**
60
     * @{inheritDoc}
61
     */
62 31
    public function key()
63
    {
64 31
        return $this->key;
65
    }
66
67
    /**
68
     * @{inheritDoc}
69
     */
70 31
    public function next()
71
    {
72 31
        $this->key += 1;
73 31
    }
74
75
    /**
76
     * @{inheritDoc}
77
     */
78 31
    public function valid()
79
    {
80 31
        return true;
81
    }
82
83
    /**
84
     * This method is called by var_dump() when dumping an object to get the properties that should be shown.
85
     *
86
     * @link http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.debuginfo
87
     * @return array
88
     */
89 1
    public function __debugInfo()
90
    {
91 1
        $info = ['__length__' => 'infinite'];
92 1
        $count = 0;
93 1
        foreach ($this as $key => $value) {
94 1
            $info[$key] = $value;
95 1
            if ($count++ >= 4) {
96 1
                break;
97
            }
98
        }
99 1
        return $info;
100
    }
101
}
102