| Total Complexity | 6 |
| Total Lines | 34 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 9 | class IpAddress implements ValueObject |
||
| 10 | { |
||
| 11 | /** @var string */ |
||
| 12 | private $ipAddress; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @throws \InvalidArgumentException if IP address is not valid |
||
| 16 | */ |
||
| 17 | public function __construct(string $ipAddress) |
||
| 18 | { |
||
| 19 | if (filter_var($ipAddress, FILTER_VALIDATE_IP) === false) { |
||
| 20 | throw new \InvalidArgumentException(sprintf('The value %s is not a valid IP address.', $ipAddress)); |
||
| 21 | } |
||
| 22 | |||
| 23 | $this->ipAddress = $ipAddress; |
||
| 24 | } |
||
| 25 | |||
| 26 | public function getIpAddress() : string |
||
| 27 | { |
||
| 28 | return $this->ipAddress; |
||
| 29 | } |
||
| 30 | |||
| 31 | public function equals(?ValueObject $object) : bool |
||
| 32 | { |
||
| 33 | if (!$object instanceof self) { |
||
| 34 | return false; |
||
| 35 | } |
||
| 36 | |||
| 37 | return $object->getIpAddress() === $this->getIpAddress(); |
||
| 38 | } |
||
| 39 | |||
| 40 | public function __toString() : string |
||
| 43 | } |
||
| 44 | } |
||
| 45 |