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 4510f04

Browse filesBrowse files
[Console] fix return type declarations
1 parent e5368e4 commit 4510f04
Copy full SHA for 4510f04

File tree

3 files changed

+16
-14
lines changed
Filter options

3 files changed

+16
-14
lines changed

‎Application.php

Copy file name to clipboardExpand all lines: Application.php
+3-9Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
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;
2524
use Symfony\Component\Console\Formatter\OutputFormatter;
2625
use Symfony\Component\Console\Helper\DebugFormatterHelper;
2726
use Symfony\Component\Console\Helper\FormatterHelper;
@@ -457,13 +456,8 @@ public function add(Command $command)
457456
return null;
458457
}
459458

460-
if (null === $command->getDefinition()) {
461-
throw new LogicException(sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', \get_class($command)));
462-
}
463-
464-
if (!$command->getName()) {
465-
throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', \get_class($command)));
466-
}
459+
// Will throw if the command is not correctly initialized.
460+
$command->getDefinition();
467461

468462
$this->commands[$command->getName()] = $command;
469463

@@ -1023,7 +1017,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
10231017
/**
10241018
* Gets the name of the command based on input.
10251019
*
1026-
* @return string The command name
1020+
* @return string|null
10271021
*/
10281022
protected function getCommandName(InputInterface $input)
10291023
{

‎Command/Command.php

Copy file name to clipboardExpand all lines: Command/Command.php
+12-4Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class Command
4040
private $aliases = [];
4141
private $definition;
4242
private $hidden = false;
43-
private $help;
44-
private $description;
43+
private $help = '';
44+
private $description = '';
4545
private $ignoreValidationErrors = false;
4646
private $applicationDefinitionMerged = false;
4747
private $applicationDefinitionMergedWithArgs = false;
@@ -105,7 +105,7 @@ public function setHelperSet(HelperSet $helperSet)
105105
/**
106106
* Gets the helper set.
107107
*
108-
* @return HelperSet A HelperSet instance
108+
* @return HelperSet|null A HelperSet instance
109109
*/
110110
public function getHelperSet()
111111
{
@@ -115,7 +115,7 @@ public function getHelperSet()
115115
/**
116116
* Gets the application instance for this command.
117117
*
118-
* @return Application An Application instance
118+
* @return Application|null An Application instance
119119
*/
120120
public function getApplication()
121121
{
@@ -347,6 +347,10 @@ public function setDefinition($definition)
347347
*/
348348
public function getDefinition()
349349
{
350+
if (null === $this->definition) {
351+
throw new LogicException(sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', \get_class($this)));
352+
}
353+
350354
return $this->definition;
351355
}
352356

@@ -453,6 +457,10 @@ public function setProcessTitle($title)
453457
*/
454458
public function getName()
455459
{
460+
if (!$this->name) {
461+
throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', \get_class($this)));
462+
}
463+
456464
return $this->name;
457465
}
458466

‎Question/Question.php

Copy file name to clipboardExpand all lines: Question/Question.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public function setNormalizer(callable $normalizer)
228228
*
229229
* The normalizer can ba a callable (a string), a closure or a class implementing __invoke.
230230
*
231-
* @return callable
231+
* @return callable|null
232232
*/
233233
public function getNormalizer()
234234
{

0 commit comments

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