Skip to content

Commit

Permalink
Merge branch '3.4' into 4.3
Browse files Browse the repository at this point in the history
* 3.4:
  [Console] allow Command::getName() to return null
  • Loading branch information
nicolas-grekas committed Aug 30, 2019
2 parents de63799 + 0c8d9a8 commit 2886902
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Symfony\Component\Console\Exception\CommandNotFoundException;
use Symfony\Component\Console\Exception\ExceptionInterface;
use Symfony\Component\Console\Exception\NamespaceNotFoundException;
use Symfony\Component\Console\Exception\LogicException;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Helper\DebugFormatterHelper;
use Symfony\Component\Console\Helper\FormatterHelper;
Expand Down Expand Up @@ -477,6 +478,10 @@ public function add(Command $command)
// 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) {
Expand Down
6 changes: 1 addition & 5 deletions Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,14 +445,10 @@ public function setProcessTitle($title)
/**
* 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;
}

Expand Down

0 comments on commit 2886902

Please sign in to comment.