Skip to content

Commit

Permalink
Improve URI internal codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Jun 30, 2024
1 parent c19e6d5 commit 37b6676
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions uri/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,17 @@ private function __construct(
*/
private function formatScheme(?string $scheme): ?string
{
if (null === $scheme || array_key_exists($scheme, self::SCHEME_DEFAULT_PORT)) {
return $scheme;
}

$formattedScheme = strtolower($scheme);
if (array_key_exists($formattedScheme, self::SCHEME_DEFAULT_PORT) || 1 === preg_match(self::REGEXP_SCHEME, $formattedScheme)) {
return $formattedScheme;
$formattedScheme = $scheme;
if (null !== $scheme) {
$formattedScheme = strtolower($scheme);
}

throw new SyntaxError('The scheme `'.$scheme.'` is invalid.');
return match (true) {
null === $formattedScheme,
array_key_exists($formattedScheme, self::SCHEME_DEFAULT_PORT),
1 === preg_match(self::REGEXP_SCHEME, $formattedScheme) => $formattedScheme,
default => throw new SyntaxError('The scheme `'.$scheme.'` is invalid.'),
};
}

/**
Expand Down

0 comments on commit 37b6676

Please sign in to comment.