Passed
Push — main ( 2c3026...24d2e8 )
by Pol
03:12
created

InfiniteIteratorAggregate   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 23
ccs 6
cts 6
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getIterator() 0 5 1
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 Iterator;
14
use IteratorAggregate;
15
use Traversable;
16
17
/**
18
 * @template TKey
19
 * @template T
20
 *
21
 * @implements IteratorAggregate<TKey, T>
22
 */
23
final class InfiniteIteratorAggregate implements IteratorAggregate
24
{
25
    /**
26
     * @var CachingIteratorAggregate<TKey, T>
27
     */
28
    private CachingIteratorAggregate $iterator;
29
30
    /**
31
     * @param Iterator<TKey, T> $iterator
32
     */
33 1
    public function __construct(Iterator $iterator)
34
    {
35 1
        $this->iterator = new CachingIteratorAggregate($iterator);
36 1
    }
37
38
    /**
39
     * @return Generator<TKey, T>
40
     */
41 1
    public function getIterator(): Traversable
42
    {
43 1
        yield from $this->iterator;
44
45 1
        yield from $this;
46
    }
47
}
48