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::getWebsite()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
ccs 0
cts 8
cp 0
rs 9.4285
cc 3
eloc 8
nc 3
nop 1
crap 12
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