Completed
Branch master (a31674)
by Radosław
02:21
created

FixedArityFn::getArity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Baethon\Phln;
5
6
final class FixedArityFn implements FixedArityInterface
7
{
8
    /**
9
     * @type integer
10
     */
11
    private $arity;
12
13
    /**
14
     * @type callable
15
     */
16
    private $fn;
17
18
    private function __construct(int $arity, callable $fn)
19
    {
20
        $this->arity = $arity;
21
        $this->fn = $fn;
22
    }
23
24
    public function getArity(): int
25
    {
26
        return $this->arity;
27
    }
28
29
    public static function of(int $arity, callable $fn): self
30
    {
31
        return new static($arity, $fn);
32
    }
33
34
    public function __invoke(...$args)
35
    {
36
        return call_user_func_array($this->fn, array_slice($args, 0, $this->arity));
37
    }
38
}
39