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.

CollectorMergerCollector::cancel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php declare(strict_types=1);
2
3
namespace ReactInspector\Collector\Merger;
4
5
use ReactInspector\CollectorInterface;
6
use ReactInspector\Measurement;
7
use ReactInspector\Measurements;
8
use ReactInspector\Metric;
9
use ReactInspector\Tags;
10
use Rx\Observable;
11
use function ApiClients\Tools\Rx\observableFromArray;
12
use function ApiClients\Tools\Rx\unwrapObservableFromPromise;
13
use function array_key_exists;
14
use function array_merge;
15
use function array_values;
16
use function assert;
17
use function current;
18
use function get_class;
19
use function React\Promise\all;
20
21
final class CollectorMergerCollector implements CollectorInterface
22
{
23
    /** @var array<int, CollectorInterface> */
24
    private array $collectors = [];
25
26
    /**
27
     * @param array<int, CollectorInterface> $collectors
28
     */
29
    public function __construct(CollectorInterface ...$collectors)
30
    {
31
        $previousClass = get_class(current($collectors));
32
        foreach ($collectors as $collector) {
33
            if (get_class($collector) !== $previousClass) {
34
                throw CollectorsMustBeOfTheSameClassException::fromCollectors(...$collectors);
35
            }
36
37
            $previousClass = get_class($collector);
38
        }
39
40
        $this->collectors = $collectors;
41
    }
42
43
    public function collect(): Observable
44
    {
45
        $promises = [];
46
47
        foreach ($this->collectors as $collector) {
48
            $promises[] = $collector->collect()->toArray()->toPromise();
49
        }
50
51
        return unwrapObservableFromPromise(
52
            all($promises)->then(static function (array $metricCollections): Observable {
53
                $metrics = [];
54
55
                foreach ($metricCollections as $metricCollection) {
56
                    foreach ($metricCollection as $metric) {
57
                        assert($metric instanceof Metric);
58
                        if (! array_key_exists($metric->config()->name(), $metrics)) {
59
                            $metrics[$metric->config()->name()] = Metric::create($metric->config(), new Tags(), new Measurements());
60
                        }
61
62
                        $measurements = [];
63
64
                        foreach ($metric->measurements()->get() as $measurement) {
65
                            $measurements[] = new Measurement(
66
                                $measurement->value(),
67
                                new Tags(...array_values(array_merge($metric->tags()->get(), $measurement->tags()->get())))
68
                            );
69
                        }
70
71
                        $metrics[$metric->config()->name()] = Metric::create(
72
                            $metric->config(),
73
                            new Tags(),
74
                            new Measurements(...array_merge($metrics[$metric->config()->name()]->measurements()->get(), $measurements))
75
                        );
76
                    }
77
                }
78
79
                return observableFromArray($metrics);
80
            })
81
        );
82
    }
83
84
    public function cancel(): void
85
    {
86
        // void
87
    }
88
}
89