Passed
Push — master ( 519921...cb1b1b )
by Pol
50:23 queued 48:27
created

Y   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 13 1
A on() 0 3 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 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
     *
25
     * @psalm-param callable $f
26
     *
27
     * @param callable $f
28
     */
29 1
    public function __construct(callable $f)
30
    {
31 1
        $this->f = $f;
32 1
    }
33
34
    /**
35
     * @psalm-return Closure(Closure(callable): mixed): mixed
36
     */
37 1
    public function __invoke()
38
    {
39 1
        $callable = $this->f;
40
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 1
                }
46
            );
47 1
        };
48
49 1
        return M::with()($f);
50
    }
51
52
    /**
53
     * @param callable $a
54
     *
55
     * @return Closure
56
     */
57 1
    public static function on(callable $a): Closure
58
    {
59 1
        return (new self($a))();
60
    }
61
}
62