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 ( 0a96e9...52ccb9 )
by
unknown
10s
created

HeaderCollectorMiddleware   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 89.47%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 0
loc 63
ccs 17
cts 19
cp 0.8947
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A post() 0 14 4
A extractHeaders() 0 18 4
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)
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