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

RepeatIterator::rewind()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 RepeatIterator
14
 *
15
 * @package Zicht\Itertools\lib
16
 */
17
class RepeatIterator implements \Countable, InfiniteIterableInterface
18
{
19
    use InfiniteIterableTrait;
20
21
    /** @var mixed */
22
    private $mixed;
23
24
    /** @var integer */
25
    private $times;
26
27
    /** @var integer */
28
    private $key;
29
30
    /**
31
     * RepeatIterator constructor.
32
     *
33
     * @param mixed $mixed
34
     * @param integer $times
35
     */
36 5
    public function __construct($mixed, $times)
37
    {
38 5
        $this->mixed = $mixed;
39 5
        $this->times = $times;
40 5
        $this->key = 0;
41 5
    }
42
43
    /**
44
     * @{inheritDoc}
45
     */
46 5
    public function rewind()
47
    {
48 5
        $this->key = 0;
49 5
    }
50
51
    /**
52
     * @{inheritDoc}
53
     */
54 4
    public function current()
55
    {
56 4
        return $this->mixed;
57
    }
58
59
    /**
60
     * @{inheritDoc}
61
     */
62 4
    public function key()
63
    {
64 4
        return $this->key;
65
    }
66
67
    /**
68
     * @{inheritDoc}
69
     */
70 4
    public function next()
71
    {
72 4
        $this->key += 1;
73 4
    }
74
75
    /**
76
     * @{inheritDoc}
77
     */
78 5
    public function valid()
79
    {
80 5
        return null === $this->times ? true : $this->key < $this->times;
81
    }
82
83
    /**
84
     * @{inheritDoc}
85
     */
86 5
    public function count()
87
    {
88 5
        return null === $this->times ? -1 : $this->times;
89
    }
90
}
91