| Total Complexity | 7 |
| Total Lines | 66 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 11 | final class OpenAddingIterator implements AddingIterator |
||
| 12 | { |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Ctor. |
||
| 16 | * |
||
| 17 | * @param Iterator&ArrayAccess $added iterator with stored values. |
||
| 18 | */ |
||
| 19 | public function __construct( |
||
| 20 | /** |
||
| 21 | * Iterator with stored values. |
||
| 22 | * |
||
| 23 | * @var Iterator&ArrayAccess |
||
| 24 | */ |
||
| 25 | private Iterator|ArrayAccess $added |
||
| 26 | ) { |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * {@inheritDoc} |
||
| 31 | */ |
||
| 32 | public function from(Iterator $source): AddingIterator |
||
| 33 | { |
||
| 34 | $updated = clone $this->added; |
||
| 35 | $updated[$source->key()] ??= $source->current(); |
||
| 36 | return new self($updated); |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * {@inheritDoc} |
||
| 41 | */ |
||
| 42 | public function current(): mixed |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * {@inheritDoc} |
||
| 49 | */ |
||
| 50 | public function key(): mixed |
||
| 51 | { |
||
| 52 | return $this->added->key(); |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * {@inheritDoc} |
||
| 57 | */ |
||
| 58 | public function next(): void |
||
| 59 | { |
||
| 60 | $this->added->next(); |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * {@inheritDoc} |
||
| 65 | */ |
||
| 66 | public function valid(): bool |
||
| 67 | { |
||
| 68 | return $this->added->valid(); |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * {@inheritDoc} |
||
| 73 | */ |
||
| 74 | public function rewind(): void |
||
| 77 | } |
||
| 78 | } |
||
| 79 |