public function withPort($port)
{
if (!(is_integer($port) || is_string($port) && is_numeric($port))) {
throw new InvalidArgumentException(sprintf('Invalid port "%s" specified; must be an integer or integer string', is_object($port) ? get_class($port) : gettype($port)));
}
$port = (int) $port;
if ($port === $this->port) {
// Do nothing if no change was made.
return clone $this;
}
if ($port < 1 || $port > 65535) {
throw new InvalidArgumentException(sprintf('Invalid port "%d" specified; must be a valid TCP/UDP port', $port));
}
$new = clone $this;
$new->port = $port;
return $new;
}