tarsana /
functional
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
|
|||
| 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 |
It seems like you are assigning to a variable which was imported through a
usestatement 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
Change visible in outer-scope