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.
Completed
Pull Request — master (#13)
by Jérémy
04:00 queued 02:10
created

WaterfallTrait::callOnce()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace CapMousse\ReactRestify\Traits;
4
5
trait WaterfallTrait
6
{
7
    /**
8
     * Call callback one
9
     * @param  \Closure $fn 
10
     * @return \Closure
11
     */
12
    private function callOnce ($fn) 
13
    {
14
        return function (...$args) use ($fn) {
15
            if ($fn === null) return;
16
            $fn(...$args);
17
            $fn = null;
1 ignored issue
show
Unused Code introduced by
$fn is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
18
        };
19
    }
20
21
    /**
22
     * Run tasks in series
23
     * @param  \Closure[]  $tasks 
24
     * @param  array       $args
25
     * @return void
26
     */
27
    private function waterfall (array $tasks, array $args)
28
    {
29
        $index = 0;
30
31
        $next = function () use (&$index, &$tasks, &$next, &$args) {
32
            if ($index == count($tasks)) { 
33
                return;
34
            }
35
            
36
            $callback = $this->callOnce(function () use (&$next) {
37
                $next();
38
            });
39
40
            $tasks[$index++]($callback, ...$args);
41
        };
42
43
        $next();
44
    }
45
}