IterableIterator::current()   A
last analyzed

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 2
Bugs 1 Features 0
Metric Value
cc 1
eloc 1
c 2
b 1
f 0
nc 1
nop 0
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 Generator;
13
use Iterator;
14
15
/**
16
 * @template TKey
17
 * @template T
18
 *
19
 * @implements Iterator<TKey, T>
20
 */
21
final class IterableIterator implements Iterator
22
{
23
    /**
24
     * @var ClosureIterator<TKey, T>
25
     */
26
    private ClosureIterator $iterator;
27
28
    /**
29
     * @param iterable<TKey, T> $iterable
30
     */
31 7
    public function __construct(iterable $iterable)
32
    {
33 7
        $this->iterator = new ClosureIterator(
34
            /**
35
             * @param iterable<TKey, T> $iterable
36
             *
37
             * @return Generator<TKey, T>
38
             */
39 7
            static fn (iterable $iterable): Generator => yield from $iterable,
40 7
            [$iterable]
41 7
        );
42
    }
43
44
    /**
45
     * @return T
46
     */
47 5
    public function current(): mixed
48
    {
49 5
        return $this->iterator->current();
50
    }
51
52
    /**
53
     * @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...
54
     */
55 2
    public function key(): mixed
56
    {
57 2
        return $this->iterator->key();
58
    }
59
60 4
    public function next(): void
61
    {
62 4
        $this->iterator->next();
63
    }
64
65 1
    public function rewind(): void
66
    {
67 1
        $this->iterator->rewind();
68
    }
69
70 4
    public function valid(): bool
71
    {
72 4
        return $this->iterator->valid();
73
    }
74
}
75