CountIterator::valid()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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