Passed
Push — main ( a0be7d...405102 )
by Pol
06:03 queued 02:49
created

ClosureIterator::getInnerIterator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
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 Generator;
13
use Iterator;
14
15
/**
16
 * @template TKey
17
 * @template T
18
 *
19
 * @implements Iterator<TKey, T>
20
 */
21
final class ClosureIterator implements Iterator
22
{
23
    /**
24
     * @var callable(mixed ...$parameters): iterable<TKey, T>
25
     */
26
    private $callable;
27
28
    /**
29
     * @var Generator<TKey, T, mixed, void>
30
     */
31
    private Generator $generator;
32
33
    /**
34
     * @var iterable<int, mixed>
35
     */
36
    private iterable $parameters;
37
38
    /**
39
     * @param callable(mixed ...$parameters): iterable<TKey, T> $callable
40
     * @param iterable<int, mixed> $parameters
41
     */
42
    public function __construct(callable $callable, iterable $parameters = [])
43
    {
44
        $this->callable = $callable;
45
        $this->parameters = $parameters;
46
        $this->generator = $this->getGenerator();
47
    }
48
49
    /**
50
     * @return T
0 ignored issues
show
Bug introduced by
The type loophp\iterators\T was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
51
     */
52
    public function current()
53
    {
54
        return $this->generator->current();
55
    }
56
57
    /**
58
     * @return TKey
0 ignored issues
show
Bug introduced by
The type loophp\iterators\TKey was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
59
     */
60
    public function key()
61
    {
62
        return $this->generator->key();
63
    }
64
65
    public function next(): void
66
    {
67
        $this->generator->next();
68
    }
69
70
    public function rewind(): void
71
    {
72
        $this->generator = $this->getGenerator();
73
    }
74
75
    public function valid(): bool
76
    {
77
        return $this->generator->valid();
78
    }
79
80
    /**
81
     * @return Generator<TKey, T, mixed, void>
82
     */
83
    private function getGenerator(): Generator
84
    {
85
        yield from ($this->callable)(...$this->parameters);
86
    }
87
}
88