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

ConcatIterableAggregate::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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
     * @var iterable<mixed, iterable<TKey, T>>
27
     */
28
    private iterable $iterables;
29
30
    /**
31
     * @param iterable<mixed, iterable<TKey, T>> $iterables
32
     */
33 1
    public function __construct(iterable $iterables)
34
    {
35 1
        $this->iterables = $iterables;
36 1
    }
37
38
    /**
39
     * @return Generator<TKey, T>
40
     */
41 1
    public function getIterator(): Generator
42
    {
43 1
        $iterator = new AppendIterator();
44
45 1
        foreach ($this->iterables as $iterable) {
46 1
            $iterator->append(
47 1
                new NoRewindIterator((new IterableIteratorAggregate($iterable))->getIterator())
48
            );
49
        }
50
51 1
        yield from $iterator;
52 1
    }
53
}
54