Skip to content
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

Closed
wants to merge 5 commits into from

Conversation

SpacePossum
Copy link
Contributor

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
License MIT

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).

@GuilhemN
Copy link
Contributor

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.

@unkind
Copy link
Contributor

unkind commented Jul 19, 2016

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 false result? Try to add command again?

@GuilhemN
Copy link
Contributor

Nothing in the core but it might be useful in third party libraries. At least more that returning one of the parameter passed.

@SpacePossum
Copy link
Contributor Author

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.
So it might make more sense to either throw an exception or allow adding a disabled command so it can be enabled later on and still be used. (and updating the PHPDoc and test would be nice as well ;) )

@linaori
Copy link
Contributor

linaori commented Jul 20, 2016

I think the behavior was correct, just need to update the docblock.

@SpacePossum
Copy link
Contributor Author

SpacePossum commented Jul 20, 2016

Updated the doc and the return value.
SF switched to explicit null return to support the new return void 'type' right?
(i.e. fabbot is wrong on this one)

@@ -360,7 +360,7 @@ public function add(Command $command)
if (!$command->isEnabled()) {
$command->setApplication(null);

return;
return null;
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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.

@unkind
Copy link
Contributor

unkind commented Jul 20, 2016

Nothing in the core but it might be useful in third party libraries.

I think that @return bool is poor replacement for exceptions when it is supposed to describe whether command (in general meaning of this term, not CLI one) succeeded.

@SpacePossum
Copy link
Contributor Author

SpacePossum commented Jul 20, 2016

@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 :)

@javiereguiluz
Copy link
Member

👍

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
Copy link
Member

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.

Copy link
Contributor Author

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
*/
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Symfony version (count is src folder only)
3.0 (a84ea7a):
Number of private methods: 1005, with PHPDoc 589, with comment 0
2.5 (5c83d12):
Number of private methods: 873, with PHPDoc 546, with comment 0

(but maybe my script is off?)

Copy link
Member

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

Copy link
Contributor Author

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 :)

@SpacePossum SpacePossum changed the title [Console] Application incorrect return null by add and register method [Console] Application update PHPDoc of add and register methods Jul 23, 2016
@@ -335,6 +335,8 @@ public function register($name)
/**
* Adds an array of command objects.
*
* @see Application::add()
Copy link
Member

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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about inline?

Copy link
Contributor Author

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

@SpacePossum
Copy link
Contributor Author

cleaned up to the minimal of changes to get the type hint correct on end points

@nicolas-grekas
Copy link
Member

Thank you @SpacePossum.

nicolas-grekas added a commit that referenced this pull request Jul 26, 2016
…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
@SpacePossum SpacePossum deleted the patch-2 branch July 26, 2016 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants