Conditions | 2 |
Paths | 1 |
Total Lines | 32 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 2 |
Changes | 0 |
1 | <?php |
||
24 | 48 | public function __invoke(): Closure |
|
25 | { |
||
26 | 48 | return |
|
27 | /** |
||
28 | * @param callable((T|V), T, TKey, iterable<TKey, T>): (T|V) $callback |
||
29 | * |
||
30 | * @return Closure(iterable<TKey, T>): Generator<TKey|int, T|V> |
||
31 | */ |
||
32 | 48 | static fn (callable $callback): Closure => |
|
33 | /** |
||
34 | * @param iterable<TKey, T> $iterable |
||
35 | * |
||
36 | * @return Generator<TKey|int, T|V> |
||
37 | */ |
||
38 | 48 | static function (iterable $iterable) use ($callback): Generator { |
|
39 | 48 | $iteratorAggregate = new IterableIteratorAggregate($iterable); |
|
40 | |||
41 | 48 | $iteratorInitial = $iteratorAggregate->getIterator(); |
|
42 | |||
43 | 48 | if (false === $iteratorInitial->valid()) { |
|
44 | 10 | return; |
|
45 | } |
||
46 | |||
47 | 38 | $initial = $iteratorInitial->current(); |
|
48 | |||
49 | /** @var Closure(iterable<TKey, T>): Generator<TKey|int, T|V> $pipe */ |
||
50 | 38 | $pipe = (new Pipe())()( |
|
51 | 38 | (new Tail())(), |
|
52 | 38 | (new Reduction())()($callback)($initial), |
|
53 | 38 | ); |
|
54 | |||
55 | 38 | yield from $pipe($iteratorAggregate); |
|
56 | 48 | }; |
|
59 |