RepeatIterator   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 4 1
A valid() 0 4 2
A __construct() 0 6 1
A rewind() 0 4 1
A key() 0 4 1
A next() 0 4 1
A count() 0 4 2
1
<?php
2
/**
3
 * @copyright Zicht Online <http://zicht.nl>
4
 */
5
6
// phpcs:disable Zicht.Commenting.PropertyComment.VarTypeAvoidMixed
7
8
namespace Zicht\Itertools\lib;
9
10
use Zicht\Itertools\lib\Interfaces\InfiniteIterableInterface;
11
use Zicht\Itertools\lib\Traits\InfiniteIterableTrait;
12
13
class RepeatIterator implements \Countable, InfiniteIterableInterface
14
{
15
    use InfiniteIterableTrait;
16
17
    /** @var mixed */
18
    private $mixed;
19
20
    /** @var int */
21
    private $times;
22
23
    /** @var int */
24
    private $key;
25
26
    /**
27
     * @param mixed $mixed
28
     * @param int $times
29
     */
30 5
    public function __construct($mixed, $times)
31
    {
32 5
        $this->mixed = $mixed;
33 5
        $this->times = $times;
34 5
        $this->key = 0;
35 5
    }
36
37
    /**
38
     * {@inheritDoc}
39
     */
40 5
    public function rewind()
41
    {
42 5
        $this->key = 0;
43 5
    }
44
45
    /**
46
     * {@inheritDoc}
47
     */
48 4
    public function current()
49
    {
50 4
        return $this->mixed;
51
    }
52
53
    /**
54
     * {@inheritDoc}
55
     */
56 4
    public function key()
57
    {
58 4
        return $this->key;
59
    }
60
61
    /**
62
     * {@inheritDoc}
63
     */
64 4
    public function next()
65
    {
66 4
        $this->key += 1;
67 4
    }
68
69
    /**
70
     * {@inheritDoc}
71
     */
72 5
    public function valid()
73
    {
74 5
        return null === $this->times ? true : $this->key < $this->times;
75
    }
76
77
    /**
78
     * {@inheritDoc}
79
     */
80 5
    public function count()
81
    {
82 5
        return null === $this->times ? -1 : $this->times;
83
    }
84
}
85