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 ( 501b75...4a5724 )
by Daniel
06:47
created

Url   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
dl 0
loc 89
ccs 33
cts 36
cp 0.9167
rs 10
c 0
b 0
f 0
wmc 16
lcom 1
cbo 2

9 Methods

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