Total Complexity | 7 |
Total Lines | 57 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
18 | class IPAddress |
||
19 | { |
||
20 | public const IPV4_SEPARATOR = '.'; |
||
21 | public const IPV6_SEPARATOR = ':'; |
||
22 | |||
23 | /** |
||
24 | * Performs the validation of the IP Address. |
||
25 | * |
||
26 | * @param string $ip_address |
||
27 | * |
||
28 | * @return bool |
||
29 | */ |
||
30 | public static function Validate(string $ip_address): bool |
||
31 | { |
||
32 | if (str_contains($ip_address, IPAddress::IPV4_SEPARATOR)) { |
||
33 | return self::validateIPv4Address($ip_address); |
||
34 | } |
||
35 | |||
36 | if (str_contains($ip_address, IPAddress::IPV6_SEPARATOR)) { |
||
37 | return self::validateIPv6Address($ip_address); |
||
38 | } |
||
39 | |||
40 | return false; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Performs a IPv4 validation. |
||
45 | * |
||
46 | * Validate an IPv4 address |
||
47 | * |
||
48 | * @param string $ip_address |
||
49 | * |
||
50 | * @return bool |
||
51 | */ |
||
52 | private static function validateIPv4Address(string $ip_address): bool |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Performs a IPv6 validation. |
||
63 | * |
||
64 | * @param string $ip_address |
||
65 | * |
||
66 | * @return bool |
||
67 | */ |
||
68 | private static function validateIPv6Address(string $ip_address): bool |
||
77 |