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
Branch ci-improvements (db65bf)
by Daniel
01:43
created

Url   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 78
rs 10
c 0
b 0
f 0
wmc 14
lcom 1
cbo 2

8 Methods

Rating   Name   Duplication   Size   Complexity  
A verifyAndGetDNS() 0 8 2
A __construct() 0 21 4
A getIp() 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 7 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
    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