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 ( c20117...e9301e )
by Daniel
02:01
created

Url::getIp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
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
29
        return $domainIp;
30
    }
31
32
    public function __construct(string $url)
33
    {
34
        $this->inputUrl = $url;
35
        $parser = new UriParser();
36
        $this->parsedUrl = $parser->parse($this->inputUrl);
37
38
        // Verify parsing has a host
39
        if (is_null($this->parsedUrl['host'])) {
40
            $this->parsedUrl = $parser->parse('https://'.$this->inputUrl);
41
            if (is_null($this->parsedUrl['host'])) {
42
                throw InvalidUrl::couldNotDetermineHost($url);
43
            }
44
        }
45
46
        if (! filter_var($this->getValidUrl(), FILTER_VALIDATE_URL)) {
47
            throw InvalidUrl::couldNotValidate($url);
48
        }
49
50
        $this->ipAddress = self::verifyAndGetDNS($this->parsedUrl['host']);
51
        $this->validatedURL = $url;
52
    }
53
54
    public function getIp(): string
55
    {
56
        return $this->ipAddress;
57
    }
58
59
    public function getInputUrl(): string
60
    {
61
        return $this->inputUrl;
62
    }
63
64
    public function getHostName(): string
65
    {
66
        return $this->parsedUrl['host'];
67
    }
68
69
    public function getValidatedURL(): string
70
    {
71
        return $this->validatedURL;
72
    }
73
74
    public function getPort(): string
75
    {
76
        return (isset($this->parsedUrl['port'])) ? $this->parsedUrl['port'] : '443';
77
    }
78
79
    public function getTestURL(): string
80
    {
81
        return "{$this->getHostName()}:{$this->getPort()}";
82
    }
83
84
    public function getValidUrl(): string
85
    {
86
        if ($this->getPort() === '80') {
87
            return 'http://'.$this->getHostName().'/';
88
        }
89
90
        return 'https://'.$this->getHostName().'/';
91
    }
92
}
93