Total Complexity | 6 |
Total Lines | 62 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | class IPValidate |
||
9 | { |
||
10 | /** |
||
11 | * @var string $ipV4 type. |
||
12 | * @var string $ipV6 type. |
||
13 | */ |
||
14 | private $ipV4 = FILTER_FLAG_IPV4; |
||
15 | private $ipV6 = FILTER_FLAG_IPV6; |
||
16 | |||
17 | |||
18 | |||
19 | /** |
||
20 | * Valide an IP Address. |
||
21 | * |
||
22 | * @param string $ipAddress to validate. |
||
23 | * |
||
24 | * @return bool |
||
25 | */ |
||
26 | 1 | public function isValid(string $ipAddress) : bool |
|
29 | } |
||
30 | |||
31 | |||
32 | |||
33 | /** |
||
34 | * Get an IP Address type. |
||
35 | * |
||
36 | * @param string $ipAddress to get type for. |
||
37 | * |
||
38 | * @return string |
||
39 | */ |
||
40 | 1 | public function getType(string $ipAddress) : string |
|
41 | { |
||
42 | 1 | $type = ""; |
|
43 | |||
44 | switch ($ipAddress) { |
||
45 | 1 | case (filter_var($ipAddress, FILTER_VALIDATE_IP, $this->ipV4)): |
|
46 | 1 | $type = "IPv4"; |
|
47 | 1 | break; |
|
48 | 1 | case (filter_var($ipAddress, FILTER_VALIDATE_IP, $this->ipV6)): |
|
49 | 1 | $type = "IPv6"; |
|
50 | 1 | break; |
|
51 | } |
||
52 | |||
53 | 1 | return $type; |
|
54 | } |
||
55 | |||
56 | |||
57 | |||
58 | /** |
||
59 | * Get IP Address Domain name if exists and IP is valid. |
||
60 | * |
||
61 | * @param string $ipAddress IP Address to get the domain name for. |
||
62 | * |
||
63 | * @return string |
||
64 | */ |
||
65 | 1 | public function getDomain(string $ipAddress) : string |
|
70 | } |
||
71 | } |
||
72 |