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   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 15.79%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 39
ccs 3
cts 19
cp 0.1579
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A determineUserAgent() 0 18 2
A getWebsite() 0 15 3
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