| Total Complexity | 7 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 6 | final class CurriedFn implements FixedArityInterface |
||
| 7 | { |
||
| 8 | /** |
||
| 9 | * @type callable |
||
| 10 | */ |
||
| 11 | private $fn; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @type integer |
||
| 15 | */ |
||
| 16 | private $arity; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @type array |
||
| 20 | */ |
||
| 21 | private $args = []; |
||
| 22 | |||
| 23 | private function __construct(int $arity, callable $fn, array $args = []) |
||
| 24 | { |
||
| 25 | $this->arity = $arity; |
||
| 26 | $this->fn = $fn; |
||
| 27 | $this->args = $args; |
||
| 28 | } |
||
| 29 | |||
| 30 | public static function of(callable $fn): self |
||
| 31 | { |
||
| 32 | return ($fn instanceof static) |
||
| 33 | ? new static($fn->arity, $fn->fn, $fn->args) |
||
| 34 | : static::ofN(Phln::arity($fn), $fn); |
||
| 35 | } |
||
| 36 | |||
| 37 | public static function ofN(int $arity, callable $fn): self |
||
| 40 | } |
||
| 41 | |||
| 42 | public function __invoke(...$args) |
||
| 43 | { |
||
| 44 | $allArgs = array_merge($this->args, $args); |
||
| 45 | |||
| 46 | return ($this->arity > count($allArgs)) |
||
| 47 | ? new static($this->arity, $this->fn, $allArgs) |
||
| 48 | : call_user_func_array($this->fn, $allArgs); |
||
| 49 | } |
||
| 50 | |||
| 51 | public function getArity(): int |
||
| 54 | } |
||
| 55 | } |
||
| 56 |