GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Trampoline   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 77
ccs 16
cts 18
cp 0.8889
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __invoke() 0 4 1
A bounce() 0 4 1
A run() 0 16 4
A __callStatic() 0 4 1
1
<?php
2
3
namespace FunctionalPHP\Trampoline;
4
5
class Trampoline
6
{
7
    /** @var  callable $f */
8
    private $f;
9
10
    /** @var  array $args */
11
    private $args;
12
13
    /**
14
     * @param callable $f
15
     * @param array $args
16
     */
17
    protected function __construct(callable $f, array $args = array())
18
    {
19 1
        $this->f = $f;
20 1
        $this->args = $args;
21 1
    }
22
23
    /**
24
     * Invoke the stored function with the stored arguments.
25
     *
26
     * @return mixed
27
     */
28
    public function __invoke()
29
    {
30 1
        return call_user_func_array($this->f, $this->args);
31
    }
32
33
    /**
34
     * Create a new trampoline instance for the given function and arguments.
35
     *
36
     * @param callable $f
37
     * @param array ...$args
38
     * @return static|callable
39
     */
40
    public static function bounce(callable $f, ...$args)
41
    {
42 1
        return new static($f, $args);
43
    }
44
45
    /**
46
     * Run a callable or a Trampoline until it gets to the final result
47
     * (ie: not a Trampoline instance)
48
     *
49
     * @param callable|Trampoline $f
50
     * @param array ...$args
51
     * @return mixed
52
     */
53
    public static function run($f, ...$args)
54
    {
55 1
        if($f instanceof self) {
56 1
            $return = $f;
57 1
        } else if(is_callable($f)) {
58 1
            $return = call_user_func_array($f, $args);
59 1
        } else  {
60 1
            throw new \RuntimeException('Expected a callable or an instance of Trampoline.');
61
        }
62
63 1
        while($return instanceof self) {
64 1
            $return = $return();
65 1
        }
66
67 1
        return $return;
68
    }
69
70
    /**
71
     * Helper function to easily run a callable as a Trampoline.
72
     *
73
     * @param string $name
74
     * @param array $arguments
75
     * @return mixed
76
     */
77
    public static function __callStatic($name, $arguments)
78
    {
79 1
        return static::run($name, ...$arguments);
80
    }
81
}