Passed
Push — main ( eef38b...6ea3e4 )
by Pol
01:52
created

MapIterableAggregate   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 29
ccs 6
cts 6
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getIterator() 0 4 2
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 Closure;
13
use Generator;
14
use IteratorAggregate;
15
16
/**
17
 * @template TKey
18
 * @template T
19
 * @template W
20
 *
21
 * @implements IteratorAggregate<TKey, W>
22
 */
23
final class MapIterableAggregate implements IteratorAggregate
24
{
25
    /**
26
     * @var Closure(T, TKey, iterable<TKey, T>): W
27
     */
28
    private Closure $closure;
29
30
    /**
31
     * @var iterable<TKey, T>
32
     */
33
    private iterable $iterable;
34
35
    /**
36
     * @param iterable<TKey, T> $iterable
37
     * @param (Closure(T, TKey, iterable<TKey, T>): W) $closure
0 ignored issues
show
Documentation Bug introduced by
The doc comment (Closure(T, TKey, iterable<TKey, T>): W) at position 1 could not be parsed: Expected ')' at position 1, but found 'Closure'.
Loading history...
38
     */
39 1
    public function __construct(iterable $iterable, Closure $closure)
40
    {
41 1
        $this->iterable = $iterable;
42 1
        $this->closure = $closure;
43
    }
44
45
    /**
46
     * @return Generator<TKey, W>
47
     */
48 1
    public function getIterator(): Generator
49
    {
50 1
        foreach ($this->iterable as $key => $value) {
51 1
            yield $key => ($this->closure)($value, $key, $this->iterable);
52
        }
53
    }
54
}
55