Completed
Push — master ( b03e32...44190a )
by Sérgio
03:19
created

curry.php ➔ curry()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2
Metric Value
cc 2
eloc 9
nc 1
nop 1
dl 0
loc 17
ccs 8
cts 8
cp 1
crap 2
rs 9.4285
1
<?php
2
3
namespace Sergiors\Functional;
4
5
/**
6
 * @author Sérgio Rafael Siqueira <[email protected]>
7
 *
8
 * @param \Closure|string $fn
9
 *
10
 * @return mixed
11
 */
12
function curry($fn)
13
{
14 22
    $args = tail(func_get_args());
15 22
    $params = (new \ReflectionFunction($fn))->getNumberOfRequiredParameters();
16
17
    return function () use ($fn, $args, $params) {
18 22
        $args = array_merge($args, func_get_args());
19
20 22
        if ($params > count($args)) {
21 13
            array_unshift($args, $fn);
22
23 13
            return call_user_func_array(__NAMESPACE__.'\curry', $args);
24
        }
25
26 22
        return call_user_func_array($fn, $args);
27 22
    };
28
}
29