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   A

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;
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
}