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

B::on()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
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 B.
12
 *
13
 * @psalm-template AType
14
 * @psalm-template BType
15
 * @psalm-template CType
16
 */
17
final class B 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
     * B constructor.
36 1
     *
37
     * @psalm-param callable(AType): BType $f
38 1
     * @psalm-param callable(CType): AType $g
39 1
     * @psalm-param CType $x
40 1
     *
41 1
     * @param callable $f
42
     * @param callable $g
43
     * @param mixed $x
44
     */
45
    public function __construct(callable $f, callable $g, $x)
46 1
    {
47
        $this->f = $f;
48 1
        $this->g = $g;
49
        $this->x = $x;
50
    }
51
52
    /**
53
     * @psalm-return BType
54 1
     */
55
    public function __invoke()
56
    {
57 1
        return ($this->f)(($this->g)($this->x));
58 1
    }
59
60
    /**
61
     * @param callable $a
62
     *
63
     * @return Closure
64
     */
65
    public static function on(callable $a): Closure
66
    {
67
        return static function (callable $b) use ($a): Closure {
68
            return static function ($c) use ($a, $b) {
69
                return (new self($a, $b, $c))();
70
            };
71
        };
72
    }
73
}
74