-
Notifications
You must be signed in to change notification settings - Fork 94
Console commands #45
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 commands #45
Conversation
❤️ ❤️ ❤️ |
I'd like the |
Basically the extension related to DIC should not do anything if this parameter is null :) |
@lookyman Just tested it. Works great 👍
|
29, | ||
], | ||
[ | ||
'Parameter #5 $default of method Symfony\Component\Console\Command\Command::addOption() expects string|false|null, int given.', |
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.
This appears to be wrong - the doc is
* @param string|string[]|int|bool|null $default The default value (must be null for InputOption::VALUE_NONE)
so i'm seeing this reported for my calls to to addOption
where I'm passing 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.
Although its true that getOption
has return type of string|string[]|bool|null
- which will likely also be wrong in this case... maybe the symfony docblock needs to be fixed
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.
The thing is, if you pass the option from the console, you can only ever get string there (or bool in case of VALUE_NONE, or null if you don't pass the option at all). You can pass a different type as a default, but that is imho wrong (as suggested by the docblock), and there is a rule that should forbid that.
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.
So there are two options here: 1) go with the docblock and just restrict it's allowed types based on the mode, or 2) union with the default's type, even if it's not allowed by the docblock. I went with the first approach. Do you suggest we should go with the second? I realize that the code does not forbid that, just the docblock, so it should be ok, I just don't think it's the intended behaviour. And I specifically added the Invalid(Argument|Option)DefaultValueRule for these cases.
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.
Interestingly this was just recently changed in Symfony - symfony/symfony#29201 - seems there is a bit of inconsistency here in the docblocks and the code, the ArgvInput
, normally used will only ever give you strings, but the ArrayInput
, often used for testing, lets you pass int
(or whatever else).
I guess given the reality is your going to get strings out for real usage, might be best to stick with what you've done. Might be also be nice to check the args to ArrayInput
are also strings([]) so users dont test with different types.
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 know what, I actually for some reason missed that the addOption
method allows int
in default. I guess I should reflect that after all.
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.
@mcfedr done
@ondrejmirtes done |
closes #20, closes #36
@mcfedr @Jean85 Can you guys test this?