bug #33385 [Console] allow Command::getName() to return null (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

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

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

As reported on 4510f04e70 (commitcomment-34845639)

Commits
-------

59ad6c29d1 [Console] allow Command::getName() to return null
This commit is contained in:
Robin Chalas 2019-08-29 18:31:21 +02:00
commit 720ffd869e
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;
}