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.

PrinterMiddleware::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 12
rs 10
cc 2
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
namespace ReactInspector\Http\Middleware\Printer;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Psr\Http\Message\ServerRequestInterface;
7
use React\Cache\ArrayCache;
8
use React\Cache\CacheInterface;
9
use React\Promise\PromiseInterface;
10
use ReactInspector\Metric;
11
use ReactInspector\MetricsStreamInterface;
12
use ReactInspector\Printer\Printer;
13
use RingCentral\Psr7\Response;
14
use function assert;
15
16
final class PrinterMiddleware
17
{
18
    private const TTL = 120;
19
20
    private Printer $printer;
21
22
    private CacheInterface $metrics;
23
24
    /** @var array<string, string> */
25
    private array $metricsList = [];
26
27
    public function __construct(Printer $printer, MetricsStreamInterface $metricsStream)
28
    {
29
        $this->printer = $printer;
30
        $this->metrics = new ArrayCache();
31
        $metricsStream->subscribe(function (Metric $metric): void {
32
            $this->metrics->set($metric->config()->name(), $metric, self::TTL);
33
            $this->metricsList[$metric->config()->name()] = $metric->config()->name();
34
        });
35
    }
36
37
    public function __invoke(ServerRequestInterface $request): PromiseInterface
38
    {
39
        /** @psalm-suppress TooManyTemplateParams */
40
        return $this->metrics->getMultiple($this->metricsList)->then(function (array $metrics): ResponseInterface {
41
            $body = '';
42
43
            foreach ($metrics as $metric) {
44
                assert($metric instanceof Metric);
45
                $body .= $this->printer->print($metric);
46
            }
47
48
            return new Response(200, [], $body);
49
        });
50
    }
51
}
52