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

Y::on()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
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 Closure;
8
use loophp\combinator\Combinator;
9
10
/**
11
 * Class Y.
12
 *
13
 * @psalm-template ResultType
14
 */
15
final class Y extends Combinator
16
{
17
    /**
18
     * @var callable
19
     */
20
    private $f;
21
22
    /**
23
     * Y constructor.
24 1
     *
25
     * @psalm-param callable $f
26 1
     *
27 1
     * @param callable $f
28
     */
29
    public function __construct(callable $f)
30
    {
31
        $this->f = $f;
32 1
    }
33
34 1
    /**
35
     * @psalm-return Closure(Closure(callable): mixed): mixed
36
     */
37 1
    public function __invoke()
38
    {
39 1
        $callable = $this->f;
40 1
41
        $f = static function (callable $f) use ($callable): Closure {
42 1
            return $callable(
43
                static function (...$arguments) use ($f) {
44 1
                    return M::with()($f)(...$arguments);
45
                }
46
            );
47
        };
48
49
        return M::with()($f);
50 1
    }
51
52
    /**
53 1
     * @param callable $a
54 1
     *
55
     * @return Closure
56
     */
57
    public static function on(callable $a): Closure
58
    {
59
        return (new self($a))();
60
    }
61
}
62