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 ( 60f956...362ca9 )
by Cees-Jan
03:57
created

InfiniteCaller::call()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 4.125

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 4
cts 8
cp 0.5
rs 9.7333
c 0
b 0
f 0
cc 3
nc 2
nop 1
crap 4.125
1
<?php declare(strict_types=1);
2
3
namespace WyriHaximus\Recoil;
4
5
use Recoil\Kernel;
6
use Rx\DisposableInterface;
7
use Rx\ObservableInterface;
8
use Rx\Subject\Subject;
9
10
final class InfiniteCaller implements QueueCallerInterface
11
{
12
    /** @var Kernel */
13
    private $kernel;
14
15
    /** @var State */
16
    private $state;
17
18
    /** @var QueueCallerInterface[] */
19
    private $callers = [];
20
21
    /** @var string[] */
22
    private $readyCallers = [];
23
24
    /** @var State[] */
25
    private $callerState = [];
26
27
    /** @var Subject */
28
    private $callerStream = [];
29
30
    /**
31
     * @param Kernel $kernel
32
     */
33 1
    public function __construct(Kernel $kernel)
34
    {
35 1
        $this->kernel = $kernel;
36
37 1
        $this->state = new State();
38 1
        $this->state->onNext(State::WAITING);
39 1
    }
40
41 1
    public function call(ObservableInterface $observable): State
42
    {
43
        try {
44
            $observable->subscribe(function (Call $call) {
45
                try {
46 1
                    $this->delegateCall($call);
47
                } catch (\Throwable $et) {
48
                    echo (string)$et;
49
                }
50 1
            });
51
        } catch (\Throwable $et) {
52
            echo (string)$et;
53
        }
54
55 1
        return $this->state;
56
    }
57
58 1
    private function delegateCall(Call $call): void
59
    {
60
        /*if (count($this->readyCallers) > 0) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
61
            $qcHash = array_pop($this->readyCallers);
62
            $this->callerStream[$qcHash]->onNext($call);
63
64
            return;
65
        }*/
66
67 1
        $stream = new Subject();
68 1
        $caller = new QueueCaller($this->kernel);
69 1
        $qcHash = spl_object_hash($caller);
70
71 1
        $this->callers[$qcHash] = $caller;
72 1
        $this->callerStream[$qcHash] = $stream;
73 1
        $this->callerState[$qcHash] = $caller->call($stream);
74
        /** @var DisposableInterface $disposeable */
75
        $disposeable = $this->callerState[$qcHash]->filter(function (int $state) {
0 ignored issues
show
Unused Code introduced by
$disposeable 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...
76 1
            return $state === State::WAITING;
77
        })->subscribe(function () use (&$disposeable, $stream, $call) {
78 1
            $stream->onNext($call);
79 1
            $disposeable->dispose();
80 1
        });
81 1
    }
82
}
83