Passed
Push — master ( 2236ae...d0b86a )
by Pol
11:24
created

Reduce::of()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace loophp\fpt;
6
7
use Closure;
8
9
use function call_user_func_array;
10
11
// phpcs:disable Generic.Files.LineLength.TooLong
12
13
/**
14
 * @psalm-immutable
15
 */
16
final class Reduce
17
{
18
    /**
19
     * @psalm-pure
20
     */
21
    public static function of(): Closure
22
    {
23
        return static fn (callable $callable): Closure => static fn (iterable $iterable): Closure => static function ($init = null) use ($callable, $iterable) {
24
            foreach ($iterable as $item) {
25
                $init = call_user_func_array($callable, $init, $item);
0 ignored issues
show
Unused Code introduced by
The call to call_user_func_array() has too many arguments starting with $item. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
                $init = /** @scrutinizer ignore-call */ call_user_func_array($callable, $init, $item);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
26
            }
27
28
            return $init;
29
        };
30
    }
31
}
32