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 ( c5b792...b2f7ce )
by Cees-Jan
03:48 queued 01:54
created

UserAgentMiddleware::pre()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 31
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5.1647

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 13
cts 16
cp 0.8125
rs 8.439
c 0
b 0
f 0
cc 5
eloc 16
nc 5
nop 2
crap 5.1647
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Middleware\UserAgent;
4
5
use ApiClients\Foundation\Middleware\DefaultPriorityTrait;
6
use ApiClients\Foundation\Middleware\ErrorTrait;
7
use ApiClients\Foundation\Middleware\MiddlewareInterface;
8
use ApiClients\Foundation\Middleware\PostTrait;
9
use Psr\Http\Message\RequestInterface;
10
use React\Promise\CancellablePromiseInterface;
11
use function React\Promise\resolve;
12
13
final class UserAgentMiddleware implements MiddlewareInterface
14
{
15
    use DefaultPriorityTrait;
16
    use PostTrait;
17
    use ErrorTrait;
18
19
    private $cache = [];
20
21
    /**
22
     * @param RequestInterface $request
23
     * @param array $options
24
     * @return CancellablePromiseInterface
25
     */
26 1
    public function pre(RequestInterface $request, array $options = []): CancellablePromiseInterface
27
    {
28 1
        if (!isset($options[UserAgentMiddleware::class][Options::STRATEGY])) {
29
            return resolve($request);
30
        }
31
32 1
        $strategy = $options[UserAgentMiddleware::class][Options::STRATEGY];
33
34 1
        if (!class_exists($strategy)) {
35
            return resolve($request);
36
        }
37
38 1
        if (!is_subclass_of($strategy, UserAgentStrategyInterface::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \ApiClients\Middleware\U...trategyInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
39
            return resolve($request);
40
        }
41
42 1
        $hash = md5(serialize($options[UserAgentMiddleware::class]));
43 1
        if (!isset($this->cache[$hash])) {
44
            /** @var UserAgentStrategyInterface $strategy */
45 1
            $strategy = new $strategy();
46
47 1
            $this->cache[$hash] = $strategy->determineUserAgent($request, $options[UserAgentMiddleware::class]);
48
        }
49
50 1
        return resolve(
51 1
            $request->withAddedHeader(
52 1
                'User-Agent',
53 1
                $this->cache[$hash]
54
            )
55
        );
56
    }
57
}
58