Passed
Push — master ( 9d4bf9...615338 )
by Radosław
02:10
created

FixedArityFn   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Baethon\Phln;
6
7
final class FixedArityFn implements FixedArityInterface
8
{
9
    private int $arity;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
10
11
    /**
12
     * @var callable
13
     */
14
    private $fn;
15
16
    private function __construct(int $arity, callable $fn)
17
    {
18
        $this->arity = $arity;
19
        $this->fn = $fn;
20
    }
21
22
    public function getArity(): int
23
    {
24
        return $this->arity;
25
    }
26
27
    public static function of(int $arity, callable $fn): self
28
    {
29
        return new static($arity, $fn);
30
    }
31
32
    /**
33
     * @param array<int, mixed> ...$args
34
     * @return mixed
35
     */
36
    public function __invoke(...$args)
37
    {
38
        return call_user_func_array($this->fn, array_slice($args, 0, $this->arity));
39
    }
40
}
41