Passed
Push — master ( f98ecf...4dc4ad )
by Pol
02:13
created

T   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 3 1
A toClosure() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace loophp\combinator\Combinator;
6
7
use loophp\combinator\Combinator;
8
9
/**
10
 * Class T.
11
 */
12
final class T extends Combinator
13
{
14
    /**
15
     * @var callable
16
     */
17
    private $f;
18
19
    /**
20
     * @var mixed
21
     */
22
    private $x;
23
24
    /**
25
     * T constructor.
26
     *
27
     * @param callable $f
28
     * @param mixed $x
29
     */
30 1
    public function __construct($x, callable $f)
31
    {
32 1
        $this->f = $f;
33 1
        $this->x = $x;
34 1
    }
35
36
    /**
37
     * @return mixed
38
     */
39 1
    public function __invoke()
40
    {
41 1
        return ($this->f)($this->x);
42
    }
43
44
    /**
45
     * @return callable
46
     */
47 1
    public static function toClosure(): callable
48
    {
49
        return static function ($x, callable $f) {
50
            return (new self($x, $f))();
51 1
        };
52
    }
53
}
54