IndexedArrayIterator::next()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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