ip = $ip ?? self::INADDR_ANY; $this->port = (int) $port; if (str_contains($port, ':')) { [$this->ip, $port] = explode(':', $port); $this->port = (int) $port; } throw_unless(filter_var($this->ip, FILTER_VALIDATE_IP) !== false, new InvalidArgumentException("$this->ip is an invalid IP address")); throw_unless($this->port > self::PORT_FLOOR, "Port $this->port must be greater than " . self::PORT_FLOOR); throw_unless($this->port < self::PORT_CEIL, "Port $this->port must be less than " . self::PORT_CEIL); } public function __toString() { if ($this->ip === self::INADDR_ANY) { return (string) $this->port; } return "$this->ip:$this->port"; } }