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.

HeaderCollectorMiddleware::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Middleware\HeaderCollector;
4
5
use ApiClients\Foundation\Middleware\ErrorTrait;
6
use ApiClients\Foundation\Middleware\MiddlewareInterface;
7
use ApiClients\Foundation\Middleware\PreTrait;
8
use Psr\Http\Message\ResponseInterface;
9
use React\Promise\CancellablePromiseInterface;
10
use function React\Promise\resolve;
11
12
final class HeaderCollectorMiddleware implements MiddlewareInterface
13
{
14
    use ErrorTrait;
15
    use PreTrait;
16
17
    /**
18
     * @var Headers
19
     */
20
    private $headers;
21
22
    /**
23
     * @param Headers $headers
24
     */
25 1
    public function __construct(Headers $headers)
26
    {
27 1
        $this->headers = $headers;
28 1
    }
29
30
    /**
31
     * @param  ResponseInterface           $response
32
     * @param  array                       $options
33
     * @return CancellablePromiseInterface
34
     *
35
     *
36
     */
37 1
    public function post(
38
        ResponseInterface $response,
39
        string $transactionId,
40
        array $options = []
41
    ): CancellablePromiseInterface {
42 1
        if (isset($options[self::class]) &&
43 1
            isset($options[self::class][Options::HEADERS]) &&
44 1
            \is_array($options[self::class][Options::HEADERS])
45
        ) {
46 1
            $this->extractHeaders($response, $options[self::class][Options::HEADERS]);
47
        }
48
49 1
        return resolve($response);
50
    }
51
52
    /**
53
     * @param ResponseInterface $response
54
     * @param array             $headers
55
     */
56 1
    private function extractHeaders(ResponseInterface $response, array $headers): void
57
    {
58 1
        $set = [];
59
60 1
        foreach ($headers as $header) {
61 1
            if (!$response->hasHeader($header)) {
62
                continue;
63
            }
64
65 1
            $set[$header] = $response->getHeaderLine($header);
66
        }
67
68 1
        if (\count($set) === 0) {
69
            return;
70
        }
71
72 1
        $this->headers->onNext($set);
73 1
    }
74
}
75