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::run()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4.0119

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 10
cts 11
cp 0.9091
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 5
nop 2
crap 4.0119
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
}