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.

Url   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getHostName() 0 4 1
A getPort() 0 4 1
B __construct() 0 22 6
1
<?php
2
3
namespace Spatie\SslCertificate;
4
5
use Spatie\SslCertificate\Exceptions\InvalidUrl;
6
7
class Url
8
{
9
    /** @var string */
10
    protected $url;
11
12
    /** @var array */
13
    protected $parsedUrl;
14
15
    public function __construct(string $url)
16
    {
17
        if (! starts_with($url, ['http://', 'https://', 'ssl://'])) {
18
            $url = "https://{$url}";
19
        }
20
21
        if (function_exists('idn_to_ascii') && strlen($url) < 61) {
22
            $url = idn_to_ascii($url, false, INTL_IDNA_VARIANT_UTS46);
23
        }
24
25
        if (! filter_var($url, FILTER_VALIDATE_URL)) {
26
            throw InvalidUrl::couldNotValidate($url);
27
        }
28
29
        $this->url = $url;
30
31
        $this->parsedUrl = parse_url($url);
0 ignored issues
show
Documentation Bug introduced by
It seems like parse_url($url) can also be of type false. However, the property $parsedUrl is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
32
33
        if (! isset($this->parsedUrl['host'])) {
34
            throw InvalidUrl::couldNotDetermineHost($this->url);
35
        }
36
    }
37
38
    public function getHostName(): string
39
    {
40
        return $this->parsedUrl['host'];
41
    }
42
43
    public function getPort(): int
44
    {
45
        return $this->parsedUrl['port'] ?? 443;
46
    }
47
}
48