Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
IteratorProxy
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
4 / 4
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 current
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 unwrap
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toArray
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Celemas\Boiler\Proxy;
6
7use Celemas\Boiler\Contract\Wrapper;
8use Iterator;
9use IteratorIterator;
10use Override;
11use Traversable;
12
13/**
14 * @api
15 *
16 * @template-covariant TKey
17 * @template-covariant TValue
18 *
19 * @template TIterator as \Traversable<TKey, TValue>
20 *
21 * @template-extends IteratorIterator<TKey, TValue, TIterator>
22 * @implements Proxy<Iterator<TKey, TValue>|null>
23 */
24final class IteratorProxy extends IteratorIterator implements Proxy
25{
26    /** @param TIterator $iterator */
27    public function __construct(
28        Traversable $iterator,
29        private readonly Wrapper $wrapper,
30    ) {
31        parent::__construct($iterator);
32    }
33
34    #[Override]
35    public function current(): mixed
36    {
37        $value = parent::current();
38
39        /** @psalm-suppress MixedReturnStatement see above */
40        return $this->wrapper->wrap($value);
41    }
42
43    #[Override]
44    public function unwrap(): ?Iterator
45    {
46        return $this->getInnerIterator();
47    }
48
49    public function toArray(): ArrayProxy
50    {
51        $inner = $this->getInnerIterator();
52
53        return new ArrayProxy($inner ? iterator_to_array($inner) : [], $this->wrapper);
54    }
55}