Passed
Push — master ( f98ecf...4dc4ad )
by Pol
02:13
created

U::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace loophp\combinator\Combinator;
6
7
use loophp\combinator\Combinator;
8
9
/**
10
 * Class U.
11
 */
12
final class U extends Combinator
13
{
14
    /**
15
     * @var callable
16
     */
17
    private $f;
18
19
    /**
20
     * @var callable
21
     */
22
    private $g;
23
24
    /**
25
     * U constructor.
26
     *
27
     * @param callable $f
28
     * @param callable $g
29
     */
30 1
    public function __construct(callable $f, callable $g)
31
    {
32 1
        $this->f = $f;
33 1
        $this->g = $g;
34 1
    }
35
36
    /**
37
     * @return mixed
38
     */
39 1
    public function __invoke()
40
    {
41 1
        $f = $this->f;
42 1
        $g = $this->g;
43
44 1
        return $g(($f($f()))($g));
45
    }
46
47
    /**
48
     * @return callable
49
     */
50 1
    public static function toClosure(): callable
51
    {
52
        return static function (callable $f, callable $g) {
53
            return (new self($f, $g))();
54 1
        };
55
    }
56
}
57