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.

WaterfallTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A callOnce() 0 8 2
A waterfall() 0 18 2
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;
0 ignored issues
show
Bug introduced by
Consider using a different name than the imported variable $fn, or did you forget to import by reference?

It seems like you are assigning to a variable which was imported through a use statement which was not imported by reference.

For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.

Change not visible in outer-scope

$x = 1;
$callable = function() use ($x) {
    $x = 2; // Not visible in outer scope. If you would like this, how
            // about using a different variable name than $x?
};

$callable();
var_dump($x); // integer(1)

Change visible in outer-scope

$x = 1;
$callable = function() use (&$x) {
    $x = 2;
};

$callable();
var_dump($x); // integer(2)
Loading history...
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
}