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.

MultiRequestCore::wait()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3.0884

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 1
dl 0
loc 17
ccs 11
cts 14
cp 0.7856
crap 3.0884
rs 9.7
c 0
b 0
f 0
1
<?php
2
3
namespace PhpBoot\RPC;
4
5
use PhpBoot\Exceptions\RpcException;
6
7
class MultiRequestCore
8
{
9
    /**
10
     * MultiRequest constructor.
11
     * @param callable[] $threads
12
     * @param callable $waitAll
13
     */
14 3
    public function __construct(array $threads, callable $waitAll)
15
    {
16 3
        foreach ($threads as $thread){
17 3
            $pos = count($this->threadResults);
18 3
            $this->threadResults[] = [null,null];
19 3
            $this->threads[] = function ()use($thread, $pos){
20
                try{
21 3
                    $this->threadResults[$pos][0] = $thread();
22 3
                }catch (\Exception $e){
23 1
                    $this->threadResults[$pos][1] = $e;
24
                }
25 3
            };
26 3
        }
27 3
        $this->waitAll = $waitAll;
28 3
    }
29
30 3
    public function run()
31
    {
32 3
        while ($thread = array_pop($this->threads)){
33 3
            $thread();
34 3
        };
35 3
    }
36
37 2
    public function wait($waitAble){
38 2
        array_push($this->waits, $waitAble);
39 2
        $this->run();
40
41 2
        if(count($this->waits)){
42 2
            $waitAll = $this->waitAll;
43 2
            $this->waitResults = $waitAll($this->waits);
44 2
            $this->waits = [];
45 2
        }
46
47 2
        $res =  array_pop($this->waitResults);
48 2
        if(isset($res[1])){
49
             \PhpBoot\abort(new RpcException($res['reason']));
50
        }else{
51 2
            return $res[0];
52
        }
53
    }
54
55
    /**
56
     * @return array
57
     */
58 3
    public function getResults()
59
    {
60 3
        return $this->threadResults;
61
    }
62
63
    /**
64
     * @var callable[]
65
     */
66
    protected $waits = [];
67
68
    /**
69
     * @var callable[]
70
     */
71
    protected $threads = [];
72
73
    protected $threadResults = [];
74
    /**
75
     * @var callable
76
     */
77
    protected $waitAll;
78
79
    /**
80
     * @var callable
81
     */
82
    protected $waitResults = [];
83
}