| Total Complexity | 10 |
| Total Lines | 69 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 6 | ||
| Bugs | 1 | Features | 1 |
| 1 | <?php |
||
| 10 | final class CartesianIterator extends MultipleIterator |
||
| 11 | { |
||
| 12 | /** @var Iterator[] */ |
||
| 13 | private $iterators = []; |
||
| 14 | |||
| 15 | /** @var int */ |
||
| 16 | private $info = 0; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @param int $flags |
||
| 20 | * @psalm-suppress ArgumentTypeCoercion |
||
| 21 | */ |
||
| 22 | 7 | public function __construct($flags = MultipleIterator::MIT_KEYS_ASSOC) |
|
| 23 | { |
||
| 24 | 7 | parent::__construct($flags | MultipleIterator::MIT_NEED_ALL); |
|
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param int $flags |
||
| 29 | * @return void |
||
| 30 | * @psalm-suppress ArgumentTypeCoercion |
||
| 31 | */ |
||
| 32 | 2 | public function setFlags($flags): void |
|
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param Iterator $iterator |
||
| 39 | * @param int|null|string $info |
||
| 40 | * @return void |
||
| 41 | */ |
||
| 42 | 7 | public function attachIterator(Iterator $iterator, $info = null): void |
|
| 43 | { |
||
| 44 | 7 | $this->iterators[] = $iterator; |
|
| 45 | 7 | parent::attachIterator($iterator, $info ?? $this->info++); |
|
| 46 | } |
||
| 47 | |||
| 48 | 2 | public function detachIterator(Iterator $iterator): void |
|
| 60 | } |
||
| 61 | |||
| 62 | 5 | public function next(int $index = 0): void |
|
| 63 | { |
||
| 64 | 5 | $iterator = $this->iterators[$index++]; |
|
| 65 | 5 | $iterator->next(); |
|
| 66 | 5 | if (!$iterator->valid() && $index < $this->countIterators()) { |
|
| 67 | 5 | $iterator->rewind(); |
|
| 68 | 5 | $this->next($index); |
|
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | 5 | public function toArray(): array |
|
| 79 | } |
||
| 80 | |||
| 81 | } |