Skip to content

Commit f392e00

Browse files
authored
[12.x] Refactor switch to match (#57236)
* Convert switch to match * fix tests
1 parent 4eff5b2 commit f392e00

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/Illuminate/Console/Parser.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,14 @@ protected static function parseArgument(string $token)
7777
{
7878
[$token, $description] = static::extractDescription($token);
7979

80-
switch (true) {
81-
case str_ends_with($token, '?*'):
82-
return new InputArgument(trim($token, '?*'), InputArgument::IS_ARRAY, $description);
83-
case str_ends_with($token, '*'):
84-
return new InputArgument(trim($token, '*'), InputArgument::IS_ARRAY | InputArgument::REQUIRED, $description);
85-
case str_ends_with($token, '?'):
86-
return new InputArgument(trim($token, '?'), InputArgument::OPTIONAL, $description);
87-
case preg_match('/(.+)\=\*(.+)/', $token, $matches):
88-
return new InputArgument($matches[1], InputArgument::IS_ARRAY, $description, preg_split('/,\s?/', $matches[2]));
89-
case preg_match('/(.+)\=(.+)/', $token, $matches):
90-
return new InputArgument($matches[1], InputArgument::OPTIONAL, $description, $matches[2]);
91-
default:
92-
return new InputArgument($token, InputArgument::REQUIRED, $description);
93-
}
80+
return match (true) {
81+
str_ends_with($token, '?*') => new InputArgument(trim($token, '?*'), InputArgument::IS_ARRAY, $description),
82+
str_ends_with($token, '*') => new InputArgument(trim($token, '*'), InputArgument::IS_ARRAY | InputArgument::REQUIRED, $description),
83+
str_ends_with($token, '?') => new InputArgument(trim($token, '?'), InputArgument::OPTIONAL, $description),
84+
(bool) preg_match('/(.+)\=\*(.+)/', $token, $matches) => new InputArgument($matches[1], InputArgument::IS_ARRAY, $description, preg_split('/,\s?/', $matches[2])),
85+
(bool) preg_match('/(.+)\=(.+)/', $token, $matches) => new InputArgument($matches[1], InputArgument::OPTIONAL, $description, $matches[2]),
86+
default => new InputArgument($token, InputArgument::REQUIRED, $description),
87+
};
9488
}
9589

9690
/**

0 commit comments

Comments
 (0)