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 ( a38759...6a612e )
by Cees-Jan
02:43
created

HeaderCollectorMiddleware   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 80.95%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 4
dl 0
loc 66
ccs 17
cts 21
cp 0.8095
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A post() 0 11 4
A priority() 0 4 1
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 ApiClients\Foundation\Middleware\Priority;
9
use Psr\Http\Message\ResponseInterface;
10
use React\Promise\CancellablePromiseInterface;
11
use function React\Promise\resolve;
12
13
final class HeaderCollectorMiddleware implements MiddlewareInterface
14
{
15
    use ErrorTrait;
16
    use PreTrait;
17
18
    /**
19
     * @var Headers
20
     */
21
    private $headers;
22
23
    /**
24
     * @param Headers $headers
25
     */
26 1
    public function __construct(Headers $headers)
27
    {
28 1
        $this->headers = $headers;
29 1
    }
30
31
    /**
32
     * @param  ResponseInterface           $response
33
     * @param  array                       $options
34
     * @return CancellablePromiseInterface
35
     */
36 1
    public function post(ResponseInterface $response, array $options = []): CancellablePromiseInterface
37
    {
38 1
        if (isset($options[self::class]) &&
39 1
            isset($options[self::class][Options::HEADERS]) &&
40 1
            is_array($options[self::class][Options::HEADERS])
41
        ) {
42 1
            $this->extractHeaders($response, $options[self::class][Options::HEADERS]);
43
        }
44
45 1
        return resolve($response);
46
    }
47
48
    /**
49
     * @return int
50
     */
51
    public function priority(): int
52
    {
53
        return Priority::LAST;
54
    }
55
56
    /**
57
     * @param ResponseInterface $response
58
     * @param array             $headers
59
     */
60 1
    private function extractHeaders(ResponseInterface $response, array $headers)
61
    {
62 1
        $set = [];
63
64 1
        foreach ($headers as $header) {
65 1
            if (!$response->hasHeader($header)) {
66
                continue;
67
            }
68
69 1
            $set[$header] = $response->getHeaderLine($header);
70
        }
71
72 1
        if (count($set) === 0) {
73
            return;
74
        }
75
76 1
        $this->headers->onNext($set);
77 1
    }
78
}
79