IndexedArrayIterator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 10
c 1
b 0
f 0
dl 0
loc 60
ccs 13
cts 13
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 3 1
A key() 0 3 1
A rewind() 0 3 1
A __construct() 0 4 1
A next() 0 3 1
A valid() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\Sequence\Iterators;
6
7
use Smoren\Sequence\Interfaces\IndexedArrayInterface;
8
use Smoren\Sequence\Interfaces\SequenceIteratorInterface;
9
10
/**
11
 * Iterator implementation for IndexedArray.
12
 *
13
 * @template T
14
 * @implements SequenceIteratorInterface<T>
15
 */
16
class IndexedArrayIterator implements SequenceIteratorInterface
17
{
18
    /**
19
     * @var IndexedArrayInterface<T> indexed array for iterating
20
     */
21
    protected IndexedArrayInterface $array;
22
    /**
23
     * @var int current iteration index
24
     */
25
    protected int $currentIndex;
26
27
    /**
28
     * IndexedArrayIterator constructor.
29
     *
30
     * @param IndexedArrayInterface<T> $array indexed array to iterate
31
     */
32 3
    public function __construct(IndexedArrayInterface $array)
33
    {
34 3
        $this->array = $array;
35 3
        $this->currentIndex = 0;
36
    }
37
38
    /**
39
     * {@inheritDoc}
40
     */
41 3
    public function current()
42
    {
43 3
        return $this->array[$this->currentIndex];
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     */
49 3
    public function next(): void
50
    {
51 3
        $this->currentIndex++;
52
    }
53
54
    /**
55
     * {@inheritDoc}
56
     */
57 3
    public function key(): int
58
    {
59 3
        return $this->currentIndex;
60
    }
61
62
    /**
63
     * {@inheritDoc}
64
     */
65 3
    public function valid(): bool
66
    {
67 3
        return isset($this->array[$this->currentIndex]);
68
    }
69
70
    /**
71
     * {@inheritDoc}
72
     */
73 3
    public function rewind(): void
74
    {
75 3
        $this->currentIndex = 0;
76
    }
77
}
78