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 ( 67970b...cc194b )
by Daniel
05:04
created

Url   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 92.5%

Importance

Changes 0
Metric Value
dl 0
loc 97
ccs 37
cts 40
cp 0.925
rs 10
c 0
b 0
f 0
wmc 18
lcom 2
cbo 1

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getTestURL() 0 4 1
A __toString() 0 4 1
A verifyAndGetDNS() 0 9 2
B __construct() 0 25 5
A getIp() 0 7 2
A getInputUrl() 0 4 1
A getHostName() 0 4 1
A getValidatedURL() 0 4 1
A getPort() 0 4 2
A getValidUrl() 0 8 2
1
<?php
2
3
namespace LiquidWeb\SslCertificate;
4
5
use League\Uri\Parser as 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 1
    public function __toString()
23
    {
24 1
        return $this->getInputUrl();
25
    }
26
27 21
    private static function verifyAndGetDNS($domain): ?string
28
    {
29 21
        $domainIp = gethostbyname($domain);
30 21
        if (! filter_var($domainIp, FILTER_VALIDATE_IP)) {
31 4
            return null;
32
        }
33
34 19
        return $domainIp;
35
    }
36
37 22
    public function __construct(string $url)
38
    {
39 22
        $this->inputUrl = $url;
40 22
        $parser = new UriParser();
41 22
        $this->parsedUrl = $parser($this->inputUrl);
42
43
        // Verify parsing has a host
44 22
        if (is_null($this->parsedUrl['host'])) {
45
            try {
46 18
                $this->parsedUrl = $parser('https://'.$this->inputUrl);
47
            } catch (\Exception $e) {
48
                throw InvalidUrl::couldNotValidate($url);
49
            }
50 18
            if (is_null($this->parsedUrl['host'])) {
51
                throw InvalidUrl::couldNotDetermineHost($url);
52
            }
53
        }
54
55 22
        if (! filter_var($this->getValidUrl(), FILTER_VALIDATE_URL)) {
56 1
            throw InvalidUrl::couldNotValidate($url);
57
        }
58
59 21
        $this->ipAddress = self::verifyAndGetDNS($this->parsedUrl['host']);
60 21
        $this->validatedURL = $url;
61 21
    }
62
63 8
    public function getIp(): ?string
64
    {
65 8
        if (null === $this->ipAddress) {
66 1
            throw InvalidUrl::couldNotResolveDns($this->inputUrl);
67
        }
68 7
        return $this->ipAddress;
69
    }
70
71 6
    public function getInputUrl(): string
72
    {
73 6
        return $this->inputUrl;
74
    }
75
76 22
    public function getHostName(): string
77
    {
78 22
        return $this->parsedUrl['host'];
79
    }
80
81 2
    public function getValidatedURL(): string
82
    {
83 2
        return $this->validatedURL;
84
    }
85
86 22
    public function getPort(): string
87
    {
88 22
        return (isset($this->parsedUrl['port'])) ? $this->parsedUrl['port'] : '443';
89
    }
90
91 12
    public function getTestURL(): string
92
    {
93 12
        return "{$this->getHostName()}:{$this->getPort()}";
94
    }
95
96 22
    public function getValidUrl(): string
97
    {
98 22
        if ($this->getPort() === '80') {
99 1
            return 'http://'.$this->getHostName().'/';
100
        }
101
102 21
        return 'https://'.$this->getHostName().'/';
103
    }
104
}
105