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

U   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

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