ParsedHostname::getSuffix()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace BenTools\HostnameExtractor;
5
6
final class ParsedHostname
7
{
8
    /**
9
     * @var string
10
     */
11
    private $subdomain;
12
13
    /**
14
     * @var string
15
     */
16
    private $domain;
17
18
    /**
19
     * @var string
20
     */
21
    private $suffix;
22
23
    /**
24
     * @var string
25
     */
26
    private $tld;
27
28
    /**
29
     * @var bool
30
     */
31
    private $isIpv4 = false;
32
33
    /**
34
     * @var bool
35
     */
36
    private $isIpv6 = false;
37
38
    /**
39
     * @return string
40
     */
41
    public function getSubdomain(): ?string
42
    {
43
        return $this->subdomain;
44
    }
45
46
    /**
47
     * @param string $subdomain
48
     */
49
    public function setSubdomain(string $subdomain): void
50
    {
51
        $this->subdomain = $subdomain;
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getSuffixedDomain(): string
58
    {
59
        return \implode(
60
            '.',
61
            \array_filter(
62
                [
63
                    $this->getDomain(),
64
                    $this->getSuffix(),
65
                ],
66
                function ($part) {
67
                    return null !== $part;
68
                }
69
            )
70
        );
71
    }
72
73
    /**
74
     * @return string
75
     */
76
    public function getDomain(): ?string
77
    {
78
        return $this->domain;
79
    }
80
81
    /**
82
     * @param string $domain
83
     */
84
    public function setDomain(string $domain): void
85
    {
86
        $this->domain = $domain;
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    public function getSuffix(): ?string
93
    {
94
        return $this->suffix;
95
    }
96
97
    /**
98
     * @param string $suffix
99
     */
100
    public function setSuffix(string $suffix): void
101
    {
102
        $this->suffix = $suffix;
103
    }
104
105
    /**
106
     * @return string
107
     */
108
    public function getTld(): ?string
109
    {
110
        return $this->tld;
111
    }
112
113
    /**
114
     * @param string $tld
115
     */
116
    public function setTld(string $tld): void
117
    {
118
        $this->tld = $tld;
119
    }
120
121
    /**
122
     * @return bool
123
     */
124
    public function isIpv4(): bool
125
    {
126
        return $this->isIpv4;
127
    }
128
129
    /**
130
     * @param bool $isIpv4
131
     */
132
    public function setIsIpv4(bool $isIpv4): void
133
    {
134
        $this->isIpv4 = $isIpv4;
135
    }
136
137
    /**
138
     * @return bool
139
     */
140
    public function isIpv6(): ?bool
141
    {
142
        return $this->isIpv6;
143
    }
144
145
    /**
146
     * @param bool $isIpv6
147
     */
148
    public function setIsIpv6(bool $isIpv6): void
149
    {
150
        $this->isIpv6 = $isIpv6;
151
    }
152
153
    /**
154
     * @return bool
155
     */
156
    public function isIp(): bool
157
    {
158
        return $this->isIpv4() || $this->isIpv6();
159
    }
160
161
    /**
162
     * @return ParsedHostname
163
     */
164
    public static function new(): self
165
    {
166
        static $prototype;
167
        if (!isset($prototype)) {
168
            $prototype = new static;
169
        }
170
        return clone $prototype;
171
    }
172
}
173