private function sanitize($url)
{
$count = 0;
if ((new StringWrapper($url))->startWith('/') === false) {
$url = '/' . $url;
}
$result = preg_replace('/\\/\\/+/', '/', $url);
$result = str_replace(':/', '://', $result, $count);
if ($result !== '/') {
$result = rtrim($result, '/');
}
if ($count > 1) {
throw new \UnexpectedValueException(sprintf('Bad URL: "%s".', $result));
}
if (false !== strpos($result, ' ')) {
throw new \UnexpectedValueException(sprintf('Bad URL: "%s". Contain white space/s.', $result));
}
return $result;
}