Unfold   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 2
eloc 8
c 1
b 1
f 0
dl 0
loc 31
ccs 8
cts 8
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 23 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace loophp\collection\Operation;
6
7
use Closure;
8
use Generator;
9
10
/**
11
 * @immutable
12
 */
13
final class Unfold extends AbstractOperation
14
{
15
    /**
16
     * @template TKey
17
     * @template T
18
     *
19
     * @return Closure(iterable<TKey, T>): Closure(callable(T...): iterable<array-key, T>): Closure(): Generator<int, iterable<array-key, T>>
20
     */
21 2
    public function __invoke(): Closure
22
    {
23 2
        return
24
            /**
25
             * @param iterable<array-key, T> $parameters
26
             *
27
             * @return Closure(callable(T...): iterable<array-key, T>): Closure(): Generator<int, iterable<array-key, T>>
28
             */
29 2
            static fn (iterable $parameters): Closure =>
30
                /**
31
                 * @param callable(T...): iterable<array-key, T> $callback
32
                 *
33
                 * @return Closure(): Generator<int, iterable<array-key, T>>
34
                 */
35 2
                static fn (callable $callback): Closure =>
36
                    /**
37
                     * @return Generator<int, iterable<array-key, T>>
38
                     */
39 2
                    static function () use ($parameters, $callback): Generator {
40 2
                        while (true) {
41 2
                            $parameters = $callback(...$parameters);
42
43 2
                            yield $parameters;
44
                        }
45 2
                    };
46
    }
47
}
48