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 ( 7f56d3...784cca )
by Cees-Jan
01:31
created

ObservableWhile::get()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 0
dl 0
loc 14
ccs 7
cts 7
cp 1
crap 4
rs 9.7998
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace WyriHaximus\Rx;
4
5
use React\Promise\Deferred;
6
use React\Promise\PromiseInterface;
7
use Rx\ObservableInterface;
8
use function React\Promise\resolve;
9
10
final class ObservableWhile
11
{
12
    /**
13
     * @var array
14
     */
15
    private $queue = [];
16
17
    /**
18
     * @var Deferred
19
     */
20
    private $deferred;
21
22
    /**
23
     * @var bool
24
     */
25
    private $done = false;
26
27
    /**
28
     * @param ObservableInterface $observable
29
     */
30
    public function __construct(ObservableInterface $observable)
31
    {
32 1
        $observable->subscribe(function ($item) {
33 1
            if ($this->deferred instanceof Deferred) {
34
                $this->deferred->resolve($item);
35
                $this->deferred = null;
36
37
                return;
38
            }
39
40 1
            $this->queue[] = $item;
41
        }, null, function () {
42 2
            $this->done = true;
43
44 2
            if ($this->deferred instanceof Deferred) {
45 1
                $this->deferred->resolve();
46 1
                $this->deferred = null;
47
            }
48 2
        });
49 2
    }
50
51 2
    public function get(): PromiseInterface
52
    {
53 2
        if (count($this->queue) === 0 && $this->done === true) {
54 1
            return resolve();
55
        }
56
57 2
        if (count($this->queue) === 0) {
58 1
            $this->deferred = new Deferred();
59
60 1
            return $this->deferred->promise();
61
        }
62
63 1
        return resolve(array_shift($this->queue));
64
    }
65
}
66