Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 720ffd8

Browse filesBrowse files
committed
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 symfony/console@4510f04#commitcomment-34845639 Commits ------- 59ad6c2 [Console] allow Command::getName() to return null
2 parents bff9574 + 59ad6c2 commit 720ffd8
Copy full SHA for 720ffd8

File tree

2 files changed

+6
-5
lines changed
Filter options

2 files changed

+6
-5
lines changed

‎src/Symfony/Component/Console/Application.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Application.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
2222
use Symfony\Component\Console\Exception\CommandNotFoundException;
2323
use Symfony\Component\Console\Exception\ExceptionInterface;
24+
use Symfony\Component\Console\Exception\LogicException;
2425
use Symfony\Component\Console\Formatter\OutputFormatter;
2526
use Symfony\Component\Console\Helper\DebugFormatterHelper;
2627
use Symfony\Component\Console\Helper\FormatterHelper;
@@ -459,6 +460,10 @@ public function add(Command $command)
459460
// Will throw if the command is not correctly initialized.
460461
$command->getDefinition();
461462

463+
if (!$command->getName()) {
464+
throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', \get_class($command)));
465+
}
466+
462467
$this->commands[$command->getName()] = $command;
463468

464469
foreach ($command->getAliases() as $alias) {

‎src/Symfony/Component/Console/Command/Command.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Command/Command.php
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,14 +453,10 @@ public function setProcessTitle($title)
453453
/**
454454
* Returns the command name.
455455
*
456-
* @return string The command name
456+
* @return string|null
457457
*/
458458
public function getName()
459459
{
460-
if (!$this->name) {
461-
throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', \get_class($this)));
462-
}
463-
464460
return $this->name;
465461
}
466462

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.