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

D::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 D.
12
 *
13
 * @psalm-template AType
14
 * @psalm-template BType
15
 * @psalm-template CType
16
 * @psalm-template DType
17
 */
18
final class D extends Combinator
19
{
20
    /**
21
     * @var callable
22
     */
23
    private $f;
24
25
    /**
26
     * @var callable
27
     */
28
    private $g;
29
30
    /**
31
     * @var mixed
32
     */
33
    private $x;
34
35
    /**
36
     * @var mixed
37
     */
38
    private $y;
39
40
    /**
41
     * D constructor.
42 1
     *
43
     * @psalm-param callable(AType): callable(CType): DType $f
44 1
     * @psalm-param AType $x
45 1
     * @psalm-param callable(BType): CType $g
46 1
     * @psalm-param BType $y
47 1
     *
48 1
     * @param callable $f
49
     * @param callable $g
50
     * @param mixed $x
51
     * @param mixed $y
52
     */
53 1
    public function __construct(callable $f, $x, callable $g, $y)
54
    {
55 1
        $this->f = $f;
56
        $this->x = $x;
57
        $this->g = $g;
58
        $this->y = $y;
59
    }
60
61 1
    /**
62
     * @psalm-return DType
63
     */
64 1
    public function __invoke()
65 1
    {
66
        return (($this->f)($this->x))(($this->g)($this->y));
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 ($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