Passed
Push — main ( e2cf3e...ef3f7a )
by Pol
17:17
created

CachingIteratorAggregate::hasNext()   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 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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
16
// phpcs:disable Generic.Files.LineLength.TooLong
17
18
/**
19
 * @template TKey
20
 * @template T
21
 *
22
 * @implements IteratorAggregate<TKey, T>
23
 */
24
final class CachingIteratorAggregate implements IteratorAggregate
25
{
26
    /**
27
     * @var SimpleCachingIteratorAggregate<int, array{0: TKey, 1:T}>
28
     */
29
    private SimpleCachingIteratorAggregate $cachingIterator;
30
31
    /**
32
     * @param Iterator<TKey, T> $iterator
33
     */
34 6
    public function __construct(Iterator $iterator)
35
    {
36 6
        $this->cachingIterator = new SimpleCachingIteratorAggregate((new PackIterableAggregate($iterator))->getIterator());
37
    }
38
39
    /**
40
     * @return Generator<TKey, T>
41
     */
42 6
    public function getIterator(): Generator
43
    {
44 6
        yield from (new UnpackIterableAggregate($this->cachingIterator))->getIterator();
45
    }
46
47 1
    public function hasNext(): bool
48
    {
49 1
        return $this->cachingIterator->hasNext();
50
    }
51
}
52