Test Failed
Push — feature/66 ( 3c1553...165ce9 )
by Max
09:45
created

BaseStorage::next()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace MaxGoryunov\SavingIterator\Src;
4
5
use Iterator;
6
7
/**
8
 * Base storage implementation.
9
 */
10
final class BaseStorage implements Storage
11
{
12
13
    /**
14
     * Ctor.
15
     * 
16
     * @param array $stored
17
     */
18
    public function __construct(
19
        /**
20
         * Stored iterator values.
21
         * 
22
         * @var array
23
         */
24
        private array $stored = []
25
    ) {
26
    }
27
28
    /**
29
     * {@inheritDoc}
30
     */
31
    public function added(Iterator $source): static
32
    {
33
        $this->stored[$source->key()] = $source->current();
34
        return $this;
35
    }
36
37
    /**
38
     * {@inheritDoc}
39
     */
40
    public function value(): mixed
41
    {
42
        return current($this->stored);
43
    }
44
45
    /**
46
     * {@inheritDoc}
47
     */
48
    public function key(): mixed
49
    {
50
        return key($this->stored);
51
    }
52
53
    public function rewind(): static
54
    {
55
        return $this;
56
    }
57
58
    public function next(): static
59
    {
60
        return $this;
61
    }
62
}
63