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

Y::closure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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