Passed
Push — master ( bef509...69203b )
by Pol
01:52
created

Y   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

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