Completed
Push — master ( d55531...cfe428 )
by Amine
02:42
created

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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 3 and the first side effect is on line 23.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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