Passed
Pull Request — master (#2)
by Pol
13:44
created

Y::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

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