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