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

Phoenix::on()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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