Passed
Push — master ( 519921...cb1b1b )
by Pol
50:23 queued 48:27
created

C::on()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace loophp\combinator\Combinator;
6
7
use Closure;
8
use loophp\combinator\Combinator;
9
10
/**
11
 * Class C.
12
 *
13
 * @psalm-template AType
14
 * @psalm-template BType
15
 * @psalm-template CType
16
 */
17
final class C extends Combinator
18
{
19
    /**
20
     * @var callable
21
     */
22
    private $f;
23
24
    /**
25
     * @var mixed
26
     */
27
    private $x;
28
29
    /**
30
     * @var mixed
31
     */
32
    private $y;
33
34
    /**
35
     * C constructor.
36
     *
37
     * @psalm-param callable(AType): callable(BType): CType $f
38
     * @psalm-param BType $x
39
     * @psalm-param AType $y
40
     *
41
     * @param callable $f
42
     * @param mixed $x
43
     * @param mixed $y
44
     */
45 1
    public function __construct(callable $f, $x, $y)
46
    {
47 1
        $this->f = $f;
48 1
        $this->x = $x;
49 1
        $this->y = $y;
50 1
    }
51
52
    /**
53
     * @psalm-return CType
54
     */
55 1
    public function __invoke()
56
    {
57 1
        return ($this->f)($this->y)($this->x);
58
    }
59
60
    /**
61
     * @param callable $a
62
     *
63
     * @return Closure
64
     */
65 1
    public static function on(callable $a): Closure
66
    {
67
        return static function ($b) use ($a): Closure {
68
            return static function ($c) use ($a, $b) {
69 1
                return (new self($a, $b, $c))();
70 1
            };
71 1
        };
72
    }
73
}
74