Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
Description
Description
With the advent of modern static analysis tools such as PHPStan and Psalm, themixed
return type fromInputInterface
'sgetArgument
andgetOption
has become somewhat tedious to interact with. I generally know at development time what the type of those return values will be based on the flags provided during the command's configuration.
It would be a nice DX improvement if there were some type-safe way to get CLI input values. This would allow removing alot of inline assertions and streamline console command implementations a decent amount.
IMO, the most straightforward approach would be adding a set ofgetArgumentAsString
(etc) methods. I don't think implementation would be too challenging, and it could probably be applied easily with a packaged trait. But it's somewhat tedious and potentially a serious BC break for any (I assume rare) custom implementations.
I could also see, potentially, having an optional second parameter to the existinggetArgument
andgetOption
methods. This, theoretically, is a bit cleaner from a BC perspective. However, for this to actually address the need of reducing inline assertions for type checkers, there would probably need to be some pretty clever generics defined on the methods. I'm notentirely sure these are possible, and they may be tooling-specific.
Thoughts? Thanks for considering!
Example
$stringArgument =$input->getArgumentAsString('name');// or$stringArgument =$input->getArgument('name', InputArgument::AS_STRING)