Total Complexity | 13 |
Total Lines | 80 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
8 | class JustifyMultipleIterator implements \Iterator |
||
9 | { |
||
10 | /** |
||
11 | * @var array<\Iterator<mixed>> |
||
|
|||
12 | */ |
||
13 | protected array $iterators = []; |
||
14 | /** |
||
15 | * @var int |
||
16 | */ |
||
17 | protected int $index = 0; |
||
18 | |||
19 | /** |
||
20 | * @param iterable<mixed> ...$iterables |
||
21 | */ |
||
22 | 374 | public function __construct(iterable ...$iterables) |
|
23 | { |
||
24 | 374 | foreach ($iterables as $iterable) { |
|
25 | 358 | $this->iterators[] = IteratorFactory::makeIterator($iterable); |
|
26 | } |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * {@inheritDoc} |
||
31 | * |
||
32 | * @return array<mixed> |
||
33 | */ |
||
34 | 318 | public function current(): array |
|
35 | { |
||
36 | 318 | return array_map( |
|
37 | 318 | fn (\Iterator $iterator) => $iterator->valid() ? $iterator->current() : NoValueMonad::getInstance(), |
|
38 | 318 | $this->iterators |
|
39 | 318 | ); |
|
40 | } |
||
41 | |||
42 | /** |
||
43 | * {@inheritDoc} |
||
44 | */ |
||
45 | 318 | public function next(): void |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * {@inheritDoc} |
||
57 | * |
||
58 | * @return int |
||
59 | */ |
||
60 | 318 | public function key(): int |
|
61 | { |
||
62 | 318 | return $this->index; |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * {@inheritDoc} |
||
67 | */ |
||
68 | 374 | public function valid(): bool |
|
77 | } |
||
78 | |||
79 | /** |
||
80 | * {@inheritDoc} |
||
81 | */ |
||
82 | 374 | public function rewind(): void |
|
88 | } |
||
89 | } |
||
90 |