| Total Complexity | 9 |
| Total Lines | 51 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | final class IPAddress extends EntityAbstract implements \Stringable |
||
| 11 | { |
||
| 12 | private string $IPAddress; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @throws \RemotelyLiving\PHPDNS\Exceptions\InvalidArgumentException |
||
| 16 | */ |
||
| 17 | public function __construct(string $IPAddress) |
||
| 18 | { |
||
| 19 | $IPAddress = trim($IPAddress); |
||
| 20 | |||
| 21 | if (!self::isValid($IPAddress)) { |
||
| 22 | throw new InvalidArgumentException("{$IPAddress} is not a valid IP address"); |
||
| 23 | } |
||
| 24 | |||
| 25 | $this->IPAddress = $IPAddress; |
||
| 26 | } |
||
| 27 | |||
| 28 | public function __toString(): string |
||
| 31 | } |
||
| 32 | |||
| 33 | public static function isValid(string $IPAddress): bool |
||
| 34 | { |
||
| 35 | return (bool) filter_var($IPAddress, FILTER_VALIDATE_IP); |
||
| 36 | } |
||
| 37 | |||
| 38 | public static function createFromString(string $IPAddress): IPAddress |
||
| 39 | { |
||
| 40 | return new self($IPAddress); |
||
| 41 | } |
||
| 42 | |||
| 43 | public function equals(IPAddress $IPAddress): bool |
||
| 44 | { |
||
| 45 | return $this->IPAddress === (string)$IPAddress; |
||
| 46 | } |
||
| 47 | |||
| 48 | public function getIPAddress(): string |
||
| 49 | { |
||
| 50 | return $this->IPAddress; |
||
| 51 | } |
||
| 52 | |||
| 53 | public function isIPv6(): bool |
||
| 56 | } |
||
| 57 | |||
| 58 | public function isIPv4(): bool |
||
| 59 | { |
||
| 61 | } |
||
| 62 | } |
||
| 63 |