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.

Metrics::removeObserver()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 5.4042

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 17
ccs 5
cts 9
cp 0.5556
rs 9.9666
c 0
b 0
f 0
cc 4
nc 3
nop 1
crap 5.4042
1
<?php declare(strict_types=1);
2
3
namespace ReactInspector;
4
5
use React\EventLoop\LoopInterface;
6
use React\EventLoop\TimerInterface;
7
use Rx\DisposableInterface;
8
use Rx\Observable;
9
use Rx\ObserverInterface;
10
use Rx\Subject\Subject;
11
use function ApiClients\Tools\Rx\observableFromArray;
12
13
final class Metrics extends Subject implements MetricsStreamInterface
14
{
15
    private LoopInterface $loop;
16
17
    private float $interval;
18
19
    private ?TimerInterface $timer = null;
20
21
    /** @var array<int, CollectorInterface> */
22
    private array $collectors = [];
23
24
    /**
25
     * @param array<int, CollectorInterface> $collectors
26
     */
27
    public function __construct(LoopInterface $loop, float $interval, CollectorInterface ...$collectors)
28
    {
29
        $this->loop       = $loop;
30
        $this->interval   = $interval;
31
        $this->collectors = $collectors;
32
    }
33
34
    public function removeObserver(ObserverInterface $observer): bool
35
    {
36
        $return = parent::removeObserver($observer);
37
        if (! $this->hasObservers()) {
38
            if ($this->timer instanceof TimerInterface) {
39 1
                $this->loop->cancelTimer($this->timer);
40
                $this->timer = null;
41 1
            }
42 1
43 1
            foreach ($this->collectors as $index => $instance) {
44 1
                $instance->cancel();
45
            }
46
47
            $this->collectors = [];
48
        }
49
50
        return $return;
51
    }
52
53
    protected function _subscribe(ObserverInterface $observer): DisposableInterface
54
    {
55
        if ($this->timer === null) {
56
            $collect     = function (): void {
57
                observableFromArray($this->collectors)->flatMap(static function (CollectorInterface $collector): Observable {
58
                    return $collector->collect();
59
                })->subscribe(function (Metric $metric): void {
60
                    $this->onNext($metric);
61
                });
62 1
            };
63
            $this->timer = $this->loop->addPeriodicTimer($this->interval, $collect);
64 1
            $collect();
65
        }
66
67 1
        return parent::_subscribe($observer);
68
    }
69
}
70