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

O   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 41
ccs 9
cts 9
cp 1
rs 10
wmc 3

3 Methods

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