ConcatIterableAggregate::getIterator()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
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 7
cts 7
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 AppendIterator;
13
use Generator;
14
use IteratorAggregate;
15
use NoRewindIterator;
16
17
/**
18
 * @template TKey
19
 * @template T
20
 *
21
 * @implements IteratorAggregate<TKey, T>
22
 */
23
final class ConcatIterableAggregate implements IteratorAggregate
24
{
25
    /**
26
     * @param iterable<mixed, iterable<TKey, T>> $iterables
27
     */
28 1
    public function __construct(private iterable $iterables)
29
    {
30 1
    }
31
32
    /**
33
     * @return Generator<TKey, T>
34
     */
35 1
    public function getIterator(): Generator
36
    {
37 1
        $iterator = new AppendIterator();
38
39 1
        foreach ($this->iterables as $iterable) {
40 1
            $iterator->append(
41 1
                new NoRewindIterator((new IterableIteratorAggregate($iterable))->getIterator())
42 1
            );
43
        }
44
45 1
        yield from $iterator;
46
    }
47
}
48