@@ -22,6 +22,9 @@ trait ExecuteMultipleCommand
2222 // Traits
2323 use GetApplication;
2424
25+ /**
26+ * @var array<int|string, string>
27+ */
2528 private array $ choices = [];
2629 /**
2730 * @psalm-suppress PropertyNotSetInConstructor
@@ -31,14 +34,13 @@ trait ExecuteMultipleCommand
3134 /**
3235 * Setter method for choices to use.
3336 *
34- * @param array $choices
37+ * @param array<int|string, string> $choices
3538 */
3639 protected function setChoices (array $ choices ): void
3740 {
3841 $ this ->choices = $ choices ;
3942 }
4043
41- /** @noinspection PhpMissingParentCallCommonInspection */
4244 /**
4345 * Executes the current command.
4446 *
@@ -53,30 +55,31 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5355 {
5456 $ this ->io = new SymfonyStyle ($ input , $ output );
5557 $ this ->io ->write ("\033\143" );
58+ $ command = $ this ->ask ();
5659
57- /** @noinspection PhpAssignmentInConditionInspection */
58- while ($ command = $ this ->ask ()) {
60+ while ($ command !== null ) {
5961 $ arguments = [
6062 'command ' => $ command ,
6163 ];
6264 $ input = new ArrayInput ($ arguments );
63- $ cmd = $ this ->getApplication ()->find ((string )$ command );
64- $ cmd ->run ($ input , $ output );
65+ $ cmd = $ this ->getApplication ()->find ($ command );
66+ $ outputValue = $ cmd ->run ($ input , $ output );
67+ $ command = $ this ->ask ();
6568 }
6669
6770 if ($ input ->isInteractive ()) {
6871 $ this ->io ->success ('Have a nice day ' );
6972 }
7073
71- return 0 ;
74+ return $ outputValue ?? 0 ;
7275 }
7376
7477 /**
7578 * Method to ask user to make choose one of defined choices.
7679 *
77- * @return string|bool
80+ * @return string|null
7881 */
79- private function ask ()
82+ private function ask (): ? string
8083 {
8184 $ index = array_search (
8285 $ this ->io ->choice ('What you want to do ' , array_values ($ this ->choices )),
@@ -85,6 +88,6 @@ private function ask()
8588 );
8689 $ choice = (string )array_values (array_flip ($ this ->choices ))[(int )$ index ];
8790
88- return $ choice === '0 ' ? false : $ choice ;
91+ return $ choice === '0 ' ? null : $ choice ;
8992 }
9093}
0 commit comments