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

E::on()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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