Passed
Push — master ( 50940b...9a4b71 )
by Pol
02:08
created

Omega   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 35
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A on() 0 3 1
A __invoke() 0 3 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 Omega.
12
 *
13
 * @psalm-template ResultType
14
 */
15
final class Omega extends Combinator
16
{
17
    /**
18
     * @var callable
19
     */
20
    private $f;
21
22
    /**
23
     * Omega constructor.
24
     *
25
     * @psalm-param callable $f
26
     *
27
     * @param callable $f
28
     */
29 2
    public function __construct(callable $f)
30
    {
31 2
        $this->f = $f;
32 2
    }
33
34
    /**
35
     * @psalm-return ResultType
36
     */
37 2
    public function __invoke()
38
    {
39 2
        return ($this->f)($this->f)(($this->f)($this->f));
40
    }
41
42
    /**
43
     * @param callable $a
44
     *
45
     * @return Closure
46
     */
47 2
    public static function on(callable $a)
48
    {
49 2
        return (new self($a))();
50
    }
51
}
52