| Total Complexity | 7 |
| Total Lines | 66 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 13 | final class ArrayAddingIterator implements AddingIterator |
||
| 14 | { |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Ctor. |
||
| 18 | * |
||
| 19 | * @phpstan-param array<TKey, TValue> $added |
||
| 20 | * @param array $added added values. |
||
| 21 | */ |
||
| 22 | public function __construct( |
||
| 23 | /** |
||
| 24 | * Added values. |
||
| 25 | * |
||
| 26 | * @var array |
||
| 27 | */ |
||
| 28 | private array $added = [] |
||
| 29 | ) { |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * {@inheritDoc} |
||
| 34 | */ |
||
| 35 | public function from(Iterator $source): AddingIterator |
||
| 36 | { |
||
| 37 | $this->added[$source->key()] ??= $source->current(); |
||
| 38 | return new self($this->added); |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * {@inheritDoc} |
||
| 43 | */ |
||
| 44 | public function current(): mixed |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * {@inheritDoc} |
||
| 51 | */ |
||
| 52 | public function key(): mixed |
||
| 53 | { |
||
| 54 | return key($this->added); |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * {@inheritDoc} |
||
| 59 | */ |
||
| 60 | public function next(): void |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * {@inheritDoc} |
||
| 67 | */ |
||
| 68 | public function valid(): bool |
||
| 69 | { |
||
| 70 | return $this->key() !== null; |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * {@inheritDoc} |
||
| 75 | */ |
||
| 76 | public function rewind(): void |
||
| 79 | } |
||
| 80 | } |
||
| 81 |