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

D   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 62
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A on() 0 6 1
A __invoke() 0 3 1
A __construct() 0 6 1
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