Total Complexity | 3 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
22 | abstract class Curry |
||
23 | { |
||
24 | /** |
||
25 | * @template T |
||
26 | * @psalm-pure |
||
27 | */ |
||
28 | 4 | public static function of(): Closure |
|
29 | { |
||
30 | return |
||
31 | /** |
||
32 | * @psalm-param positive-int|null $arity |
||
33 | */ |
||
34 | 4 | static fn (callable $callable, ?int $arity = null): Closure => |
|
35 | /** |
||
36 | * @psalm-param mixed ...$args |
||
37 | * @return mixed |
||
38 | */ |
||
39 | 4 | static fn (...$args) => static::curryN( |
|
40 | 4 | ($arity ?? (new ReflectionFunction($callable))->getNumberOfRequiredParameters()) - count($args), |
|
41 | $callable, |
||
42 | 4 | static::getArguments([], $args) |
|
43 | 4 | ); |
|
44 | } |
||
45 | |||
46 | /** |
||
47 | * @psalm-pure |
||
48 | * |
||
49 | * @psalm-param list<mixed> $args |
||
50 | * @psalm-param list<mixed> $argsNext |
||
51 | */ |
||
52 | abstract protected static function getArguments(array $args = [], array $argsNext = []): array; |
||
53 | |||
54 | /** |
||
55 | * @return mixed |
||
56 | */ |
||
57 | 4 | private static function curryN(int $numberOfArguments, callable $function, array $args = []) |
|
67 | } |
||
68 | } |
||
69 |