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

W   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 3 1
A on() 0 4 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 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