Completed
Push — master ( cfe428...5e2d42 )
by Amine
02:00
created

try.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
function numberOfArgs($fn) {
4
    $reflector = is_array($fn) ?
5
        new ReflectionMethod($fn[0], $fn[1]) :
6
        new ReflectionFunction($fn);
7
    return $reflector->getNumberOfParameters();
8
}
9
10
function curry($fn) {
11
    return curriedFunction($fn, numberOfArgs($fn));
12
}
13
14
function curriedFunction($fn, $argsCount, $boundArgs = []) {
15
    return function() use($fn, $argsCount, $boundArgs) {
16
        $boundArgs = array_merge($boundArgs, func_get_args());
0 ignored issues
show
Consider using a different name than the imported variable $boundArgs, or did you forget to import by reference?

It seems like you are assigning to a variable which was imported through a use statement which was not imported by reference.

For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.

Change not visible in outer-scope

$x = 1;
$callable = function() use ($x) {
    $x = 2; // Not visible in outer scope. If you would like this, how
            // about using a different variable name than $x?
};

$callable();
var_dump($x); // integer(1)

Change visible in outer-scope

$x = 1;
$callable = function() use (&$x) {
    $x = 2;
};

$callable();
var_dump($x); // integer(2)
Loading history...
17
        if (count($boundArgs) >= $argsCount)
18
            return call_user_func_array($fn, $boundArgs);
19
        return curriedFunction($fn, $argsCount, $boundArgs);
20
    };
21
}
22
23
$add = function($x, $y) {
24
    return $x + $y;
25
};
26
27
$add = curry($add);
28
29
$add2 = $add();
30
31
$increment = $add(1);
32
33
echo $increment(1, 2);
34