Passed
Push — master ( 0f152c...b64aff )
by Pol
22:11 queued 07:09
created

V::on()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 0
cp 0
crap 2
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 V.
12
 *
13
 * @psalm-template AType
14
 * @psalm-template BType
15
 * @psalm-template CType
16
 */
17
final class V 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
     * V constructor.
36 1
     *
37
     * @psalm-param AType $x
38 1
     * @psalm-param BType $y
39 1
     * @psalm-param callable(AType): callable(BType): CType $f
40 1
     *
41 1
     * @param mixed $x
42
     * @param mixed $y
43
     * @param callable $f
44
     */
45
    public function __construct($x, $y, callable $f)
46 1
    {
47
        $this->f = $f;
48 1
        $this->x = $x;
49
        $this->y = $y;
50
    }
51
52
    /**
53
     * @psalm-return CType
54 1
     */
55
    public function __invoke()
56
    {
57 1
        return (($this->f)($this->x))($this->y);
58 1
    }
59
60
    /**
61
     * @param callable $a
62
     *
63
     * @return Closure
64
     */
65
    public static function on($a): Closure
66
    {
67
        return static function ($b) use ($a): Closure {
68
            return static function (callable $c) use ($a, $b) {
69
                return (new self($a, $b, $c))();
70
            };
71
        };
72
    }
73
}
74