Passed
Pull Request — master (#2)
by Pol
02:21
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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
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
        /**
42
         * @psalm-suppress MissingClosureReturnType
43
         *
44
         * @param callable $f
45
         *
46
         * @return mixed
47
         */
48
        $f = static function (callable $f) use ($callable) {
49 1
            return $callable(
50
                /**
51
                 * @psalm-suppress MissingClosureParamType
52
                 *
53
                 * @param array $arguments
54
                 */
55
                static function (...$arguments) use ($f) {
56 1
                    return $f($f)(...$arguments);
57 1
                }
58
            );
59 1
        };
60
61 1
        return $f($f);
62
    }
63
}
64