Conditions | 2 |
Paths | 1 |
Total Lines | 15 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Tests | 7 |
CRAP Score | 2 |
Changes | 3 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
14 | function partial(callable $fn /* ...$args */) |
||
15 | { |
||
16 | 40 | $args = tail(func_get_args()); |
|
17 | 40 | $numRequiredParams = (new \ReflectionFunction($fn))->getNumberOfRequiredParameters(); |
|
18 | |||
19 | return function (/* ...$args */) use ($fn, $args, $numRequiredParams) { |
||
20 | 40 | $args = array_merge($args, func_get_args()); |
|
21 | |||
22 | 40 | if ($numRequiredParams > count($args)) { |
|
23 | 17 | return call_user_func_array(partial, array_merge([$fn], $args)); |
|
24 | } |
||
25 | |||
26 | 40 | return call_user_func_array($fn, $args); |
|
27 | 40 | }; |
|
28 | } |
||
29 |