MultipleIterableAggregate   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 7
c 2
b 1
f 0
dl 0
loc 25
ccs 10
cts 10
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getIterator() 0 12 2
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
16
/**
17
 * @template TKey
18
 * @template T
19
 *
20
 * @implements IteratorAggregate<array<int, TKey|null>, array<int, T|null>>
21
 */
22
final class MultipleIterableAggregate implements IteratorAggregate
23
{
24
    /**
25
     * @param iterable<array-key, iterable<TKey, T>> $iterables
26
     * @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...
27
     */
28 3
    public function __construct(private iterable $iterables, private int $flags = MultipleIterator::MIT_NEED_ALL | MultipleIterator::MIT_KEYS_NUMERIC)
29
    {
30 3
    }
31
32
    /**
33
     * @return Generator<array<int, TKey|null>, array<int, T|null>>
34
     */
35 3
    public function getIterator(): Generator
36
    {
37 3
        $mit = new MultipleIterator($this->flags);
38
39 3
        foreach ($this->iterables as $key => $iterable) {
40 3
            $mit->attachIterator(
41 3
                (new IterableIteratorAggregate($iterable))->getIterator(),
42 3
                $key
43 3
            );
44
        }
45
46 3
        yield from $mit;
47
    }
48
}
49