public function withUserInfo($user, $password = null)
{
if (!is_string($user)) {
throw new InvalidArgumentException(sprintf('%s expects a string user argument; received %s', __METHOD__, is_object($user) ? get_class($user) : gettype($user)));
}
if (null !== $password && !is_string($password)) {
throw new InvalidArgumentException(sprintf('%s expects a string password argument; received %s', __METHOD__, is_object($password) ? get_class($password) : gettype($password)));
}
$info = $user;
if ($password) {
$info .= ':' . $password;
}
if ($info === $this->userInfo) {
// Do nothing if no change was made.
return clone $this;
}
$new = clone $this;
$new->userInfo = $info;
return $new;
}