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.

UserAgentMiddleware   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 81.25%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 47
ccs 13
cts 16
cp 0.8125
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A pre() 0 34 5
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Middleware\UserAgent;
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
final class UserAgentMiddleware implements MiddlewareInterface
13
{
14
    use PostTrait;
15
    use ErrorTrait;
16
17
    private $cache = [];
18
19
    /**
20
     * @param  RequestInterface            $request
21
     * @param  array                       $options
22
     * @return CancellablePromiseInterface
23
     */
24 1
    public function pre(
25
        RequestInterface $request,
26
        string $transactionId,
27
        array $options = []
28
    ): CancellablePromiseInterface {
29 1
        if (!isset($options[UserAgentMiddleware::class][Options::STRATEGY])) {
30
            return resolve($request);
31
        }
32
33 1
        $strategy = $options[UserAgentMiddleware::class][Options::STRATEGY];
34
35 1
        if (!\class_exists($strategy)) {
36
            return resolve($request);
37
        }
38
39 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...
40
            return resolve($request);
41
        }
42
43 1
        $hash = \md5(\serialize($options[UserAgentMiddleware::class]));
44 1
        if (!isset($this->cache[$hash])) {
45
            /** @var UserAgentStrategyInterface $strategy */
46 1
            $strategy = new $strategy();
47
48 1
            $this->cache[$hash] = $strategy->determineUserAgent($request, $options[UserAgentMiddleware::class]);
49
        }
50
51 1
        return resolve(
52 1
            $request->withAddedHeader(
53 1
                'User-Agent',
54 1
                $this->cache[$hash]
55
            )
56
        );
57
    }
58
}
59