[Console] allow Command::getName() to return null

This commit is contained in:
Nicolas Grekas 2019-08-29 18:09:35 +02:00
parent 593ec61f60
commit 59ad6c29d1
2 changed files with 6 additions and 5 deletions

View File

@ -21,6 +21,7 @@ use Symfony\Component\Console\Event\ConsoleExceptionEvent;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\Console\Exception\CommandNotFoundException;
use Symfony\Component\Console\Exception\ExceptionInterface;
use Symfony\Component\Console\Exception\LogicException;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Helper\DebugFormatterHelper;
use Symfony\Component\Console\Helper\FormatterHelper;
@ -459,6 +460,10 @@ class Application
// Will throw if the command is not correctly initialized.
$command->getDefinition();
if (!$command->getName()) {
throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', \get_class($command)));
}
$this->commands[$command->getName()] = $command;
foreach ($command->getAliases() as $alias) {

View File

@ -453,14 +453,10 @@ class Command
/**
* Returns the command name.
*
* @return string The command name
* @return string|null
*/
public function getName()
{
if (!$this->name) {
throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', \get_class($this)));
}
return $this->name;
}