From 6407e7e59135b6b85d16065da3c69420949de448 Mon Sep 17 00:00:00 2001 From: Amir Hossein Shokri Date: Wed, 1 Oct 2025 18:55:12 +0330 Subject: [PATCH 1/2] Convert switch to match --- src/Illuminate/Console/Parser.php | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/Illuminate/Console/Parser.php b/src/Illuminate/Console/Parser.php index d70088e61beb..761171980dc0 100644 --- a/src/Illuminate/Console/Parser.php +++ b/src/Illuminate/Console/Parser.php @@ -77,20 +77,14 @@ protected static function parseArgument(string $token) { [$token, $description] = static::extractDescription($token); - switch (true) { - case str_ends_with($token, '?*'): - return new InputArgument(trim($token, '?*'), InputArgument::IS_ARRAY, $description); - case str_ends_with($token, '*'): - return new InputArgument(trim($token, '*'), InputArgument::IS_ARRAY | InputArgument::REQUIRED, $description); - case str_ends_with($token, '?'): - return new InputArgument(trim($token, '?'), InputArgument::OPTIONAL, $description); - case preg_match('/(.+)\=\*(.+)/', $token, $matches): - return new InputArgument($matches[1], InputArgument::IS_ARRAY, $description, preg_split('/,\s?/', $matches[2])); - case preg_match('/(.+)\=(.+)/', $token, $matches): - return new InputArgument($matches[1], InputArgument::OPTIONAL, $description, $matches[2]); - default: - return new InputArgument($token, InputArgument::REQUIRED, $description); - } + return match (true) { + str_ends_with($token, '?*') => new InputArgument(trim($token, '?*'), InputArgument::IS_ARRAY, $description), + str_ends_with($token, '*') => new InputArgument(trim($token, '*'), InputArgument::IS_ARRAY | InputArgument::REQUIRED, $description), + str_ends_with($token, '?') => new InputArgument(trim($token, '?'), InputArgument::OPTIONAL, $description), + preg_match('/(.+)\=\*(.+)/', $token, $matches) => new InputArgument($matches[1], InputArgument::IS_ARRAY, $description, preg_split('/,\s?/', $matches[2])), + preg_match('/(.+)\=(.+)/', $token, $matches) => new InputArgument($matches[1], InputArgument::OPTIONAL, $description, $matches[2]), + default => new InputArgument($token, InputArgument::REQUIRED, $description), + }; } /** From 076b54e123eca55ba96f5f48fb580751fe5c317e Mon Sep 17 00:00:00 2001 From: Amir Hossein Shokri Date: Wed, 1 Oct 2025 19:23:49 +0330 Subject: [PATCH 2/2] fix tests --- src/Illuminate/Console/Parser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Console/Parser.php b/src/Illuminate/Console/Parser.php index 761171980dc0..454d74c7d3a0 100644 --- a/src/Illuminate/Console/Parser.php +++ b/src/Illuminate/Console/Parser.php @@ -81,8 +81,8 @@ protected static function parseArgument(string $token) str_ends_with($token, '?*') => new InputArgument(trim($token, '?*'), InputArgument::IS_ARRAY, $description), str_ends_with($token, '*') => new InputArgument(trim($token, '*'), InputArgument::IS_ARRAY | InputArgument::REQUIRED, $description), str_ends_with($token, '?') => new InputArgument(trim($token, '?'), InputArgument::OPTIONAL, $description), - preg_match('/(.+)\=\*(.+)/', $token, $matches) => new InputArgument($matches[1], InputArgument::IS_ARRAY, $description, preg_split('/,\s?/', $matches[2])), - preg_match('/(.+)\=(.+)/', $token, $matches) => new InputArgument($matches[1], InputArgument::OPTIONAL, $description, $matches[2]), + (bool) preg_match('/(.+)\=\*(.+)/', $token, $matches) => new InputArgument($matches[1], InputArgument::IS_ARRAY, $description, preg_split('/,\s?/', $matches[2])), + (bool) preg_match('/(.+)\=(.+)/', $token, $matches) => new InputArgument($matches[1], InputArgument::OPTIONAL, $description, $matches[2]), default => new InputArgument($token, InputArgument::REQUIRED, $description), }; }