| Total Complexity | 8 |
| Total Lines | 69 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 2 |
| 1 | <?php |
||
| 13 | final class ValidAddingIterator implements AddingIterator |
||
| 14 | { |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Ctor. |
||
| 18 | * |
||
| 19 | * @phpstan-param AddingIterator<TKey, TValue> $origin |
||
| 20 | * @param AddingIterator $origin original adding iterator. |
||
| 21 | */ |
||
| 22 | public function __construct( |
||
| 23 | /** |
||
| 24 | * Original adding iterator. |
||
| 25 | * |
||
| 26 | * @phpstan-var AddingIterator<TKey, TValue> |
||
| 27 | * @var AddingIterator |
||
| 28 | */ |
||
| 29 | private AddingIterator $origin |
||
| 30 | ) { |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * {@inheritDoc} |
||
| 35 | * Only adds values if source is valid. |
||
| 36 | */ |
||
| 37 | public function from(Iterator $source): AddingIterator |
||
| 38 | { |
||
| 39 | return ($source->valid()) |
||
| 40 | ? new self($this->origin->from($source)) |
||
| 41 | : $this; |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * {@inheritDoc} |
||
| 46 | */ |
||
| 47 | public function current(): mixed |
||
| 48 | { |
||
| 49 | return $this->origin->current(); |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * {@inheritDoc} |
||
| 54 | */ |
||
| 55 | public function key(): mixed |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * {@inheritDoc} |
||
| 62 | */ |
||
| 63 | public function next(): void |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * {@inheritDoc} |
||
| 70 | */ |
||
| 71 | public function valid(): bool |
||
| 72 | { |
||
| 73 | return $this->origin->valid(); |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * {@inheritDoc} |
||
| 78 | */ |
||
| 79 | public function rewind(): void |
||
| 82 | } |
||
| 83 | } |
||
| 84 |