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

W::on()   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 1
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 Closure;
8
use loophp\combinator\Combinator;
9
10
/**
11
 * Class W.
12
 *
13
 * @psalm-template AType
14
 * @psalm-template BType
15
 */
16
final class W extends Combinator
17
{
18
    /**
19
     * @var callable
20
     */
21
    private $f;
22
23
    /**
24
     * @var mixed
25
     */
26
    private $x;
27
28
    /**
29
     * W constructor.
30
     *
31
     * @psalm-param callable(AType): callable(AType): BType $f
32
     * @psalm-param AType $x
33
     *
34
     * @param callable $f
35
     * @param mixed $x
36
     */
37 1
    public function __construct(callable $f, $x)
38
    {
39 1
        $this->f = $f;
40 1
        $this->x = $x;
41 1
    }
42
43
    /**
44
     * @psalm-return BType
45
     */
46 1
    public function __invoke()
47
    {
48 1
        return ($this->f)($this->x)($this->x);
49
    }
50
51
    /**
52
     * @param callable $a
53
     *
54
     * @return Closure
55
     */
56 1
    public static function on(callable $a): Closure
57
    {
58
        return static function ($b) use ($a) {
59 1
            return (new self($a, $b))();
60 1
        };
61
    }
62
}
63