Passed
Push — master ( 90528a...a31674 )
by Radosław
02:00
created

FixedArityFn   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getArity() 0 3 1
A __construct() 0 4 1
A __invoke() 0 3 1
A of() 0 3 1
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