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

L::on()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
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 L.
12
 *
13
 * @psalm-template ResultType
14
 */
15
final class L extends Combinator
16
{
17
    /**
18
     * @var callable
19
     */
20
    private $f;
21
22
    /**
23
     * @var callable
24
     */
25
    private $g;
26
27
    /**
28
     * L constructor.
29
     *
30 1
     * @param callable $f
31
     * @param callable $g
32 1
     */
33 1
    public function __construct(callable $f, callable $g)
34 1
    {
35
        $this->f = $f;
36
        $this->g = $g;
37
    }
38
39 1
    /**
40
     * @psalm-return ResultType
41 1
     *
42
     * @return mixed
43
     */
44
    public function __invoke()
45
    {
46
        return ($this->f)(($this->g)($this->g));
47 1
    }
48
49
    /**
50 1
     * @param callable $a
51 1
     *
52
     * @return Closure
53
     */
54
    public static function on(callable $a): Closure
55
    {
56
        return static function (callable $b) use ($a) {
57
            return (new self($a, $b))();
58
        };
59
    }
60
}
61