Skip to content

[Console] add union types #41912

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

Merged
merged 1 commit into from
Jul 2, 2021
Merged

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 6.0
Bug fix? no
New feature? no
Deprecations? no
Tickets Part of #41424
License MIT
Doc PR -

*
* @throws InvalidArgumentException When argument mode is not valid
*
* @return $this
*/
public function addArgument(string $name, int $mode = null, string $description = '', $default = null)
public function addArgument(string $name, int $mode = null, string $description = '', mixed $default = null)
Copy link
Member

Choose a reason for hiding this comment

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

Was the parameter annotation wrong here?

Suggested change
public function addArgument(string $name, int $mode = null, string $description = '', mixed $default = null)
public function addArgument(string $name, int $mode = null, string $description = '', string|array|null $default = null)

Copy link
Member Author

@nicolas-grekas nicolas-grekas Jun 30, 2021

Choose a reason for hiding this comment

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

Tests fail if we restrict here. We should at least allow int|float|bool. But I don't see the need to restrict when it was allowed before. We should avoid needless BC breaks IMHO.

Copy link
Member

Choose a reason for hiding this comment

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

It does not make much sense to pass a default value that cannot be produced by invoking the command via the console. null would be the only reasonable exception here.

If we don't want to break BC, I'm fine with mixed but please let's keep the more precise type in the doc block then.

Copy link
Member Author

@nicolas-grekas nicolas-grekas Jun 30, 2021

Choose a reason for hiding this comment

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

What would be the point of the annotation? If technically we don't care, we shouldn't bother our users IMHO.
I'm sure there are ppl out there that already found some creative use of that :)

Copy link
Member

Choose a reason for hiding this comment

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

I'm sure there are ppl out there that already found some creative use of that :)

That's precisely what scares me. 🙈

Copy link
Member Author

Choose a reason for hiding this comment

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

We should be proud of what ppl do with Symfony :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I did some git blame + some code inspection. We use mixed in many places already. Having this restricted list is both wrong (as proved by tests) and not needed. I confirm this change.

PR ready.

@nicolas-grekas nicolas-grekas force-pushed the unions-console branch 3 times, most recently from fde34d8 to 0b1d337 Compare June 30, 2021 16:21
* @param string $description A description text
* @param string|string[]|bool|null $default The default value (must be null for self::VALUE_NONE)
* @param $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
* @param $mode The option mode: One of the VALUE_* constants
Copy link
Contributor

Choose a reason for hiding this comment

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

IIUC we dont duplicate the type as per CS?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh wait, this is totally fine 👍

When provided it MAY contain a Type to indicate what is expected
https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/param.html#param

for now 🤦

When provided it MUST contain a "Type" to indicate what is expected
https://github.com/php-fig/fig-standards/blob/master/proposed/phpdoc-tags.md#59-param

Copy link
Member Author

@nicolas-grekas nicolas-grekas Jul 1, 2021

Choose a reason for hiding this comment

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

We settled on:

  • PSR19 is not a thing and is outdated anyway, especially considering PHP8
  • phpdoc.org is the most up-to-date specification/authority for annotations.

@nicolas-grekas nicolas-grekas merged commit cf76057 into symfony:6.0 Jul 2, 2021
@nicolas-grekas nicolas-grekas deleted the unions-console branch July 3, 2021 09:52
@wouterj wouterj mentioned this pull request Jan 3, 2024
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.

4 participants