Passed
Push — master ( e4531b...a6f95b )
by Smoren
02:40
created

SequenceIterator::current()   A

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 0
Metric Value
eloc 1
c 0
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\SequenceInterface;
8
use Smoren\Sequence\Interfaces\SequenceIteratorInterface;
9
10
/**
11
 * @template T
12
 * @implements SequenceIteratorInterface<T>
13
 */
14
class SequenceIterator implements SequenceIteratorInterface
15
{
16
    /**
17
     * @var SequenceInterface<T>
18
     */
19
    protected SequenceInterface $sequence;
20
    /**
21
     * @var int
22
     */
23
    protected int $currentIndex;
24
    /**
25
     * @var T
0 ignored issues
show
Bug introduced by
The type Smoren\Sequence\Iterators\T was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
     */
27
    protected $currentValue;
28
29
    /**
30
     * @param SequenceInterface<T> $sequence
31
     */
32 7
    public function __construct(SequenceInterface $sequence)
33
    {
34 7
        $this->sequence = $sequence;
35 7
        $this->currentIndex = 0;
36
    }
37
38
    /**
39
     * {@inheritDoc}
40
     * @return T
41
     */
42 7
    public function current()
43
    {
44 7
        return $this->currentValue;
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50 7
    public function next(): void
51
    {
52 7
        $this->currentIndex++;
53 7
        $this->currentValue = $this->sequence->getNextValue($this->currentValue);
54
    }
55
56
    /**
57
     * {@inheritDoc}
58
     */
59 7
    public function key(): int
60
    {
61 7
        return $this->currentIndex;
62
    }
63
64
    /**
65
     * {@inheritDoc}
66
     */
67 7
    public function valid(): bool
68
    {
69 7
        $count = $this->sequence->isInfinite() ? INF : $this->sequence->count();
70 7
        return $this->currentIndex >= 0 && $this->currentIndex < $count;
71
    }
72
73
    /**
74
     * {@inheritDoc}
75
     */
76 7
    public function rewind(): void
77
    {
78 7
        $this->currentIndex = 0;
79 7
        $this->currentValue = $this->sequence->getStartValue();
80
    }
81
}
82