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 ( a2f7e3...e2b627 )
by Cees-Jan
03:10 queued 01:24
created

PackageVersionStrategy::determineUserAgent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.5388

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 18
ccs 3
cts 11
cp 0.2727
rs 9.4285
cc 2
eloc 11
nc 2
nop 2
crap 3.5388
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Middleware\UserAgent\UserAgentStrategy;
4
5
use ApiClients\Middleware\UserAgent\Options;
6
use ApiClients\Middleware\UserAgent\UserAgentStrategyInterface;
7
use InvalidArgumentException;
8
use PackageVersions\Versions;
9
use function Composed\package;
10
use Psr\Http\Message\RequestInterface;
11
12
final class PackageVersionStrategy implements UserAgentStrategyInterface
13
{
14
    const USER_AGENT = '%s %s%s powered by PHP API Clients https://php-api-clients.org/';
15
16 1
    public function determineUserAgent(RequestInterface $request, array $options): string
17
    {
18 1
        if (!isset($options[Options::PACKAGE])) {
19 1
            throw new InvalidArgumentException('Missing package option');
20
        }
21
22
        $package = $options[Options::PACKAGE];
23
24
        $chunks = [];
25
        $chunks[] = $package;
26
        $chunks[] = explode('@', Versions::getVersion($package))[0];
27
        $chunks[] = $this->getWebsite($package);
28
29
        return sprintf(
30
            self::USER_AGENT,
31
            ...$chunks
32
        );
33
    }
34
35
    protected function getWebsite(string $package)
36
    {
37
        $package = package($package);
38
        $homepage = $package->getConfig('homepage');
39
40
        if ($homepage === null) {
41
            return '';
42
        }
43
44
        if (filter_var($homepage, FILTER_VALIDATE_URL) === false) {
45
            return '';
46
        }
47
48
        return ' (' . $homepage . ') ';
49
    }
50
}
51