diff --git a/src/Illuminate/Console/QuestionHelper.php b/src/Illuminate/Console/QuestionHelper.php index 64f8f26dbcd4..9905d5ef632a 100644 --- a/src/Illuminate/Console/QuestionHelper.php +++ b/src/Illuminate/Console/QuestionHelper.php @@ -3,6 +3,7 @@ namespace Illuminate\Console; use Illuminate\Console\View\Components\TwoColumnDetail; +use Illuminate\Support\Arr; use Illuminate\Support\Stringable; use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Helper\SymfonyQuestionHelper; @@ -35,28 +36,30 @@ protected function writePrompt(OutputInterface $output, Question $question): voi : 'Ctrl+D'); } - switch (true) { - case null === $default: - $text = sprintf('%s', $text); - - break; - - case $question instanceof ConfirmationQuestion: - $text = sprintf('%s (yes/no) [%s]', $text, $default ? 'yes' : 'no'); - - break; - - case $question instanceof ChoiceQuestion: - $choices = $question->getChoices(); - $text = sprintf('%s [%s]', $text, OutputFormatter::escape($choices[$default] ?? $default)); - - break; - - default: - $text = sprintf('%s [%s]', $text, OutputFormatter::escape($default)); - - break; - } + $text = match (true) { + null === $default => sprintf( + '%s', + $text + ), + + $question instanceof ConfirmationQuestion => sprintf( + '%s (yes/no) [%s]', + $text, + $default ? 'yes' : 'no' + ), + + $question instanceof ChoiceQuestion => sprintf( + '%s [%s]', + $text, + OutputFormatter::escape(Arr::get($question->getChoices(), $default, $default)), + ), + + default => sprintf( + '%s [%s]', + $text, + OutputFormatter::escape($default) + ), + }; $output->writeln($text);