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 ( b04c59...4ec6fa )
by Cees-Jan
01:28
created

ObservableWhile   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 68.75%

Importance

Changes 0
Metric Value
dl 0
loc 51
ccs 11
cts 16
cp 0.6875
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 2
A get() 0 14 4
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 1
            $this->done = true;
43 1
        });
44 1
    }
45
46 1
    public function get(): PromiseInterface
47
    {
48 1
        if (count($this->queue) === 0 && $this->done === true) {
49 1
            return resolve();
50
        }
51
52 1
        if (count($this->queue) === 0) {
53
            $this->deferred = new Deferred();
54
55
            return $this->deferred->promise();
56
        }
57
58 1
        return resolve(array_shift($this->queue));
59
    }
60
}
61