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

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