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

J::on()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
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 J.
12
 *
13
 * @psalm-template AType
14
 * @psalm-template BType
15
 */
16
final class J extends Combinator
17
{
18
    /**
19
     * @var callable
20
     */
21
    private $f;
22
23
    /**
24
     * @var mixed
25
     */
26
    private $x;
27
28
    /**
29
     * @var mixed
30
     */
31
    private $y;
32
33
    /**
34
     * @var mixed
35
     */
36
    private $z;
37
38
    /**
39
     * J constructor.
40
     *
41
     * @psalm-param callable(AType): callable(BType): BType $f
42 1
     * @psalm-param AType $x
43
     * @psalm-param BType $y
44 1
     * @psalm-param AType $z
45 1
     *
46 1
     * @param callable $f
47 1
     * @param mixed $x
48 1
     * @param mixed $y
49
     * @param mixed $z
50
     */
51
    public function __construct(callable $f, $x, $y, $z)
52
    {
53 1
        $this->f = $f;
54
        $this->x = $x;
55 1
        $this->y = $y;
56
        $this->z = $z;
57
    }
58
59
    /**
60
     * @psalm-return BType
61 1
     */
62
    public function __invoke()
63
    {
64 1
        return (($this->f)($this->x))((($this->f)($this->z))($this->y));
65 1
    }
66
67
    /**
68
     * @param callable $a
69
     *
70
     * @return Closure
71
     */
72
    public static function on(callable $a): Closure
73
    {
74
        return static function ($b) use ($a): Closure {
75
            return static function ($c) use ($a, $b): Closure {
76
                return static function ($d) use ($a, $b, $c) {
77
                    return (new self($a, $b, $c, $d))();
78
                };
79
            };
80
        };
81
    }
82
}
83