Passed
Push — master ( 519921...cb1b1b )
by Pol
50:23 queued 48:27
created

L::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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 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
     * @param callable $f
31
     * @param callable $g
32
     */
33 1
    public function __construct(callable $f, callable $g)
34
    {
35 1
        $this->f = $f;
36 1
        $this->g = $g;
37 1
    }
38
39
    /**
40
     * @psalm-return ResultType
41
     *
42
     * @return mixed
43
     */
44 1
    public function __invoke()
45
    {
46 1
        return ($this->f)(($this->g)($this->g));
47
    }
48
49
    /**
50
     * @param callable $a
51
     *
52
     * @return Closure
53
     */
54 1
    public static function on(callable $a): Closure
55
    {
56
        return static function (callable $b) use ($a) {
57 1
            return (new self($a, $b))();
58 1
        };
59
    }
60
}
61