| Total Complexity | 13 |
| Total Lines | 80 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 12 | class JustifyMultipleIterator implements \Iterator |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var array<\Iterator<mixed>> |
||
|
|
|||
| 16 | */ |
||
| 17 | protected array $iterators = []; |
||
| 18 | /** |
||
| 19 | * @var int |
||
| 20 | */ |
||
| 21 | protected int $index = 0; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param iterable<mixed> ...$iterables |
||
| 25 | */ |
||
| 26 | 734 | public function __construct(iterable ...$iterables) |
|
| 27 | { |
||
| 28 | 734 | foreach ($iterables as $iterable) { |
|
| 29 | 702 | $this->iterators[] = IteratorFactory::makeIterator($iterable); |
|
| 30 | } |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * {@inheritDoc} |
||
| 35 | * |
||
| 36 | * @return array<mixed> |
||
| 37 | */ |
||
| 38 | 622 | public function current(): array |
|
| 39 | { |
||
| 40 | 622 | return array_map( |
|
| 41 | 622 | fn (\Iterator $iterator) => $iterator->valid() ? $iterator->current() : NoValueMonad::getInstance(), |
|
| 42 | 622 | $this->iterators |
|
| 43 | 622 | ); |
|
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * {@inheritDoc} |
||
| 48 | */ |
||
| 49 | 622 | public function next(): void |
|
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * {@inheritDoc} |
||
| 61 | * |
||
| 62 | * @return int |
||
| 63 | */ |
||
| 64 | 322 | public function key(): int |
|
| 65 | { |
||
| 66 | 322 | return $this->index; |
|
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * {@inheritDoc} |
||
| 71 | */ |
||
| 72 | 734 | public function valid(): bool |
|
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * {@inheritDoc} |
||
| 85 | */ |
||
| 86 | 734 | public function rewind(): void |
|
| 92 | } |
||
| 93 | } |
||
| 94 |