New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Console] Application update PHPDoc of add and register methods #19389
Conversation
Why do we even return the command ? IMO we should instead return a boolean specifiing whether or not the command was added to the application. |
What do you suggest to do with |
Nothing in the core but it might be useful in third party libraries. At least more that returning one of the parameter passed. |
it is done so you chain things up like; $app->add(new MyCommand())->myCommandMethod('called after construction and adding'); this only works if you always get an object back. |
I think the behavior was correct, just need to update the docblock. |
Updated the doc and the return value. |
@@ -360,7 +360,7 @@ public function add(Command $command) | |||
if (!$command->isEnabled()) { | |||
$command->setApplication(null); | |||
|
|||
return; | |||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be reverted, that's the default anyway in PHP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then the docs are off;
https://github.com/symfony/symfony-docs/pull/6614/files#diff-42d49998b5b27b6669bad0e79210dee0R94
after;
#17201
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I don't agree, but fair enough.
I think that |
@unkind I agree, I would expect that the only returned value is the Command added and if it wasn't an exception was thrown. But I think the PR is a nice compromise, having a correct PHPDoc is a nice little improvement, I don't want the PR to grow bigger than needed :) |
👍 Status: reviewed |
@@ -351,7 +351,7 @@ public function addCommands(array $commands) | |||
* | |||
* @param Command $command A Command object | |||
* | |||
* @return Command The registered command | |||
* @return Command|null The registered command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should document that it returns null
when the command is not enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the docs, please take a look again :)
* @param string $string | ||
* | ||
* @return int | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👎 on this, we usually don't add this to private
methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @xabbuh , this provides no value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
happy to remove, but it does add value as it provides the type info, but fair enough :)
@@ -335,6 +335,8 @@ public function register($name) | |||
/** | |||
* Adds an array of command objects. | |||
* | |||
* @see Application::add() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't use @see
(we removed all of them recently)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about inline?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like {@inheritdoc}
? not sure, last time I played around with Sami it would not result in the docs. you prop. want, but happy to put it in there
cleaned up to the minimal of changes to get the type hint correct on end points |
Thank you @SpacePossum. |
…methods (SpacePossum) This PR was squashed before being merged into the 2.7 branch (closes #19389). Discussion ---------- [Console] Application update PHPDoc of add and register methods | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT The [PHPDoc](https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Console/Application.php#L354) states the method will always return a command, but it doesn't. Since [Application::register](https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Console/Application.php#L328) returns the result of `add` directly is also doesn't always return the command (as its PHPDoc states). Commits ------- 6f0474f [Console] Application update PHPDoc of add and register methods
The PHPDoc states the method will always return a command, but it doesn't. Since Application::register returns the result of
add
directly is also doesn't always return the command (as its PHPDoc states).