Passed
Push — master ( f6bac1...bddb58 )
by Pol
02:08
created

Reduction   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A of() 0 9 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace loophp\fpt;
6
7
use Closure;
8
9
// phpcs:disable Generic.Files.LineLength.TooLong
10
11
/**
12
 * @psalm-immutable
13
 */
14
final class Reduction
15
{
16
    /**
17
     * @psalm-pure
18
     */
19 2
    public static function of(): Closure
20
    {
21 2
        return static fn (callable ...$callables): Closure => static fn ($init = null): Closure => static function (iterable ...$iterables) use ($callables, $init) {
22 2
            foreach ($iterables as $iterable) {
23 2
                foreach ($iterable as $key => $item) {
24 2
                    yield $key => ($init = array_reduce(
25 2
                        $callables,
26 2
                        static fn ($init, callable $callback) => $callback($init, $item, $key, $iterable),
27
                        $init
28
                    ));
29
                }
30
            }
31 2
        };
32
    }
33
}
34