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

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