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 ( ecd45b...16c344 )
by Daniel
02:29
created

Url   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 90.63%

Importance

Changes 0
Metric Value
dl 0
loc 80
ccs 29
cts 32
cp 0.9063
rs 10
c 0
b 0
f 0
wmc 14
lcom 1
cbo 2

8 Methods

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