From 37b6676d39ce099ce3152fb03c525fb54787573b Mon Sep 17 00:00:00 2001 From: ignace nyamagana butera Date: Sun, 30 Jun 2024 21:12:56 +0200 Subject: [PATCH] Improve URI internal codebase --- uri/Uri.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/uri/Uri.php b/uri/Uri.php index 78ca1d28..326206cd 100644 --- a/uri/Uri.php +++ b/uri/Uri.php @@ -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.'), + }; } /**