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 ( 8301e3...554491 )
by Daniel
01:36
created

Url::isValidFqdn()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace LiquidWeb\SslCertificate;
4
5
use League\Uri\UriParser;
6
use LiquidWeb\SslCertificate\Exceptions\InvalidUrl;
7
8
class Url
9
{
10
    /** @var string */
11
    protected $inputUrl;
12
13
    /** @var array */
14
    protected $parsedUrl;
15
16
    /** @var string */
17
    protected $validatedURL;
18
19
    /** @var string */
20
    protected $ipAddress;
21
22
    private static function verifyAndGetDNS($domain): string
23
    {
24
        $domainIp = gethostbyname($domain);
25
        if (!filter_var($domainIp, FILTER_VALIDATE_IP)) {
26
            throw InvalidUrl::couldNotResolveDns($domain);
27
        }
28
        return $domainIp;
29
    }
30
31
    public function __construct(string $url)
32
    {
33
        $this->inputUrl = $url;
34
        $parser = new UriParser();
35
        $this->parsedUrl = $parser->parse($this->inputUrl);
36
37
        // Verify parsing has a host
38
        if (is_null($this->parsedUrl['host'])) {
39
            $this->parsedUrl = $parser->parse('https://'.$this->inputUrl);
40
            if (is_null($this->parsedUrl['host'])) {
41
                throw InvalidUrl::couldNotDetermineHost($url);
42
            }
43
        }
44
45
        if (! filter_var($this->getValidUrl(), FILTER_VALIDATE_URL)) {
46
            throw InvalidUrl::couldNotValidate($url);
47
        }
48
49
        $this->ipAddress = self::verifyAndGetDNS($this->parsedUrl['host']);
50
        $this->validatedURL = $url;
51
    }
52
53
    public function getIp(): string
54
    {
55
        return $this->ipAddress;
56
    }
57
58
    public function getHostName(): string
59
    {
60
        return $this->parsedUrl['host'];
61
    }
62
63
    public function getValidatedURL(): string
64
    {
65
        return $this->validatedURL;
66
    }
67
68
    public function getPort(): string
69
    {
70
        return (isset($this->parsedUrl['port'])) ? $this->parsedUrl['port'] : '443';
71
    }
72
73
    public function getTestURL(): string
74
    {
75
        return "{$this->getHostName()}:{$this->getPort()}";
76
    }
77
78
    public function getValidUrl(): string
79
    {
80
        if ($this->getPort() === '80') {
81
            return 'http://'.$this->getHostName().'/';
82
        }
83
        return 'https://'.$this->getHostName().'/';
84
    }
85
}
86