Skip to content

Commit

Permalink
Improve codebase by using match
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Aug 23, 2023
1 parent c0bf6df commit c10a585
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions BaseUri.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,11 @@ public function isCrossOrigin(Stringable|string $uri): bool
$uri = static::filterUri($uri);
$uriOrigin = $this->computeOrigin($uri, $uri instanceof Psr7UriInterface ? '' : null);

return null === $uriOrigin
|| $uriOrigin->__toString() !== $this->origin->__toString();
return match(true) {
null === $uriOrigin,
$uriOrigin->__toString() !== $this->origin->__toString() => true,
default => false,
};
}

/**
Expand Down Expand Up @@ -447,7 +450,8 @@ final protected static function formatHost(Psr7UriInterface|UriInterface $uri):

return match (true) {
null !== $converted => $uri->withHost($converted),
$uri instanceof UriInterface, '' === $host => $uri,
'' === $host,
$uri instanceof UriInterface => $uri,
default => $uri->withHost((string) Uri::fromComponents(['host' => $host])->getHost()),
};
}
Expand Down Expand Up @@ -504,20 +508,16 @@ final protected static function getSegments(string $path): array
*/
final protected static function formatPath(string $path, string $basePath): string
{
if ('' === $path) {
return in_array($basePath, ['', '/'], true) ? $basePath : './';
}

if (false === ($colonPosition = strpos($path, ':'))) {
return $path;
}

$colonPosition = strpos($path, ':');
$slashPosition = strpos($path, '/');
if (false === $slashPosition || $colonPosition < $slashPosition) {
return "./$path";
}

return $path;
return match (true) {
'' === $path => in_array($basePath, ['', '/'], true) ? $basePath : './',
false === $colonPosition => $path,
false === $slashPosition,
$colonPosition < $slashPosition => "./$path",
default => $path,
};
}

/**
Expand Down

0 comments on commit c10a585

Please sign in to comment.