Passed
Push — main ( f88c55...04db72 )
by Pol
03:43
created

MultipleIterableAggregate::getIterator()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 11
ccs 6
cts 6
cp 1
crap 2
rs 10
1
<?php
2
3
/**
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 */
7
8
declare(strict_types=1);
9
10
namespace loophp\iterators;
11
12
use Generator;
13
use IteratorAggregate;
14
use MultipleIterator;
15
use Traversable;
16
17
/**
18
 * @template TKey
19
 * @template T
20
 *
21
 * @implements IteratorAggregate<int, array<TKey, T>>
22
 */
23
final class MultipleIterableAggregate implements IteratorAggregate
24
{
25
    /**
26
     * @var (0|1|2|3)
0 ignored issues
show
Documentation Bug introduced by
The doc comment (0|1|2|3) at position 1 could not be parsed: Unknown type name '0' at position 1 in (0|1|2|3).
Loading history...
27
     */
28
    private int $flags;
29
30
    /**
31
     * @var iterable<mixed, iterable<TKey, T>>
32
     */
33
    private iterable $iterables;
34
35
    /**
36
     * @param iterable<mixed, iterable<TKey, T>> $iterables
37
     * @param (0|1|2|3) $flags
0 ignored issues
show
Documentation Bug introduced by
The doc comment (0|1|2|3) at position 1 could not be parsed: Unknown type name '0' at position 1 in (0|1|2|3).
Loading history...
38
     */
39 3
    public function __construct(iterable $iterables, int $flags = MultipleIterator::MIT_NEED_ALL | MultipleIterator::MIT_KEYS_NUMERIC)
40
    {
41 3
        $this->flags = $flags;
42 3
        $this->iterables = $iterables;
43 3
    }
44
45
    /**
46
     * @return Generator<int, array<TKey, T>>
47
     */
48 3
    public function getIterator(): Traversable
49
    {
50 3
        $mit = new MultipleIterator($this->flags);
51
52 3
        foreach ($this->iterables as $iterable) {
53 3
            $mit->attachIterator(
54 3
                (new IterableIteratorAggregate($iterable))->getIterator()
55
            );
56
        }
57
58 3
        yield from $mit;
59 3
    }
60
}
61