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
Push — master ( a445f1...b2ee95 )
by Jérémy
01:44
created

WaterfallTrait::waterfall()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 1
nop 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;
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
}