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.

TokenAuthorizationHeaderMiddleware::pre()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 3
dl 0
loc 20
ccs 9
cts 9
cp 1
crap 3
rs 9.6
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Middleware\TokenAuthorization;
4
5
use ApiClients\Foundation\Middleware\ErrorTrait;
6
use ApiClients\Foundation\Middleware\MiddlewareInterface;
7
use ApiClients\Foundation\Middleware\PostTrait;
8
use Psr\Http\Message\RequestInterface;
9
use React\Promise\CancellablePromiseInterface;
10
use function React\Promise\resolve;
11
12
/**
13
 * Middleware that adds the authorization header in the token format.
14
 */
15
class TokenAuthorizationHeaderMiddleware implements MiddlewareInterface
16
{
17
    use PostTrait;
18
    use ErrorTrait;
19
20
    /**
21
     * @param  RequestInterface            $request
22
     * @param  array                       $options
23
     * @return CancellablePromiseInterface
24
     */
25 4
    public function pre(
26
        RequestInterface $request,
27
        string $transactionId,
28
        array $options = []
29
    ): CancellablePromiseInterface {
30 4
        if (!isset($options[self::class][Options::TOKEN])) {
31 2
            return resolve($request);
32
        }
33
34 2
        if (empty($options[self::class][Options::TOKEN])) {
35 1
            return resolve($request);
36
        }
37
38 1
        return resolve(
39 1
            $request->withAddedHeader(
40 1
                'Authorization',
41 1
                'token ' . $options[self::class][Options::TOKEN]
42
            )
43
        );
44
    }
45
}
46