From 218278b9f5137be0e96e91605f04465efd6b74eb Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Wed, 8 Oct 2014 14:45:36 -0400 Subject: [PATCH 1/2] Prevent an empty choice list being passed This currently causes a max() warning in QuestionHelper::doAsk() --- .../Command/ContainerDebugCommand.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php index 74a6ded0eb319..978190be5c77d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php @@ -110,8 +110,15 @@ protected function execute(InputInterface $input, OutputInterface $output) $options = array('tag' => $tag, 'show_private' => $input->getOption('show-private')); } elseif ($name = $input->getArgument('name')) { $object = $this->getContainerBuilder(); - $name = $this->findProperServiceName($input, $output, $object, $name); - $options = array('id' => $name); + $matchedId = $this->findProperServiceName($input, $output, $object, $name); + // check to see if nothing was matched + if (false === $matchedId) { + $output->writeln(sprintf('No services found that match "%s".', $name)); + + return; + } + + $options = array('id' => $matchedId); } else { $object = $this->getContainerBuilder(); $options = array('show_private' => $input->getOption('show-private')); @@ -184,7 +191,12 @@ private function findProperServiceName(InputInterface $input, OutputInterface $o return $name; } - $question = new ChoiceQuestion('Choose a number for more information on the service', $this->findServiceIdsContaining($builder, $name)); + $matchingServices = $this->findServiceIdsContaining($builder, $name); + if (empty($matchingServices)) { + return false; + } + + $question = new ChoiceQuestion('Choose a number for more information on the service', $matchingServices); $question->setErrorMessage('Service %s is invalid.'); return $this->getHelper('question')->ask($input, $output, $question); From ee08f4152cfb8659f2536f79ac7f3ec4476a0d25 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Wed, 8 Oct 2014 14:54:56 -0400 Subject: [PATCH 2/2] Simplifying my fix --- .../Command/ContainerDebugCommand.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php index 978190be5c77d..da2f1e2f423a5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php @@ -110,15 +110,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $options = array('tag' => $tag, 'show_private' => $input->getOption('show-private')); } elseif ($name = $input->getArgument('name')) { $object = $this->getContainerBuilder(); - $matchedId = $this->findProperServiceName($input, $output, $object, $name); - // check to see if nothing was matched - if (false === $matchedId) { - $output->writeln(sprintf('No services found that match "%s".', $name)); - - return; - } - - $options = array('id' => $matchedId); + $name = $this->findProperServiceName($input, $output, $object, $name); + $options = array('id' => $name); } else { $object = $this->getContainerBuilder(); $options = array('show_private' => $input->getOption('show-private')); @@ -193,7 +186,7 @@ private function findProperServiceName(InputInterface $input, OutputInterface $o $matchingServices = $this->findServiceIdsContaining($builder, $name); if (empty($matchingServices)) { - return false; + throw new \InvalidArgumentException(sprintf('No services found that match "%s".', $name)); } $question = new ChoiceQuestion('Choose a number for more information on the service', $matchingServices);