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
Pull Request — master (#4)
by Cees-Jan
48:39 queued 38:43
created

PackageVersionStrategy::determineUserAgent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 11
nc 2
nop 1
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Foundation\Transport\UserAgentStrategy;
4
5
use ApiClients\Foundation\Transport\Options;
6
use ApiClients\Foundation\Transport\UserAgentStrategyInterface;
7
use InvalidArgumentException;
8
use PackageVersions\Versions;
9
use function Composed\package;
10
11
final class PackageVersionStrategy implements UserAgentStrategyInterface
12
{
13
    const USER_AGENT = '%s %s%s powered by PHP API Clients https://php-api-clients.org/';
14
15
    public function determineUserAgent(array $options): string
16
    {
17
        if (!isset($options[Options::PACKAGE])) {
18
            throw new InvalidArgumentException('Missing package option');
19
        }
20
21
        $package = $options[Options::PACKAGE];
22
23
        $chunks = [];
24
        $chunks[] = $package;
25
        $chunks[] = explode('@', Versions::getVersion($package))[0];
26
        $chunks[] = $this->getWebsite($package);
27
28
        return sprintf(
29
            self::USER_AGENT,
30
            ...$chunks
31
        );
32
    }
33
34
    protected function getWebsite(string $package)
35
    {
36
        $package = package($package);
37
        $homepage = $package->getConfig('homepage');
0 ignored issues
show
Documentation introduced by
'homepage' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
38
39
        if ($homepage === null) {
40
            return '';
41
        }
42
43
        if (filter_var($homepage, FILTER_VALIDATE_URL) === false) {
44
            return '';
45
        }
46
47
        return ' (' . $homepage . ') ';
48
    }
49
}
50