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.

BasicAuthorizationHeaderMiddleware::pre()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 3
dl 0
loc 30
ccs 15
cts 15
cp 1
crap 4
rs 9.44
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Middleware\BasicAuthorization;
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
final class BasicAuthorizationHeaderMiddleware implements MiddlewareInterface
16
{
17
    use PostTrait;
18
    use ErrorTrait;
19
20
    /**
21
     * @param  RequestInterface            $request
22
     * @param  array                       $options
23
     * @return CancellablePromiseInterface
24
     */
25 5
    public function pre(
26
        RequestInterface $request,
27
        string $transactionId,
28
        array $options = []
29
    ): CancellablePromiseInterface {
30 5
        if (!isset($options[self::class][Options::USERNAME])) {
31 2
            return resolve($request);
32
        }
33
34 3
        if (empty($options[self::class][Options::USERNAME])) {
35 1
            return resolve($request);
36
        }
37
38 2
        if (!\array_key_exists(Options::PASSWORD, $options[self::class])) {
39 1
            $options[self::class][Options::PASSWORD] = '';
40
        }
41
42 2
        return resolve(
43 2
            $request->withAddedHeader(
44 2
                'Authorization',
45 2
                \sprintf(
46 2
                    'Basic %s',
47 2
                    \base64_encode(
48 2
                        $options[self::class][Options::USERNAME] . ':' .
49 2
                        $options[self::class][Options::PASSWORD]
50
                    )
51
                )
52
            )
53
        );
54
    }
55
}
56