Closed
Description
This is a question, I'd be interested in implementing this, but not sure if its possible with Phpstan, so a point in the right direction would be useful.
In Symfony commands options (and arguments) are added in configure
function, and this affects the return type of $input->getOption
later.
class MyCommand {
protected function configure(): void
{
$this
->addOption('str', null, InputOption::VALUE_REQUIRED, 'This option will be ?string')
->addOption('bool', null, InputOption::VALUE_NONE, 'this option will be bool')
->addOption('arra', null, InputOption::VALUE_IS_ARRAY, 'this option will be ?(string[])')
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$str = $input->getOption('str');
}
}
So can I change the return type of getOption
, according to the options that are configured?
Metadata
Metadata
Assignees
Labels
No labels
Activity
lookyman commentedon Feb 14, 2019
I though about this before and so far I am not sure how to implement it. For example, you can have the options defined in a parent, and you should still be able to recognize their types. It gets quite complicated. I have vague ideas about using type specifying extension (define some dummy variables in the command's scope, see
PHPStan\Type\Symfony\Helper
), but nothing concrete at the moment. You can certainly give it a go, I would appreciate it!Also, #20.
ondrejmirtes commentedon Feb 14, 2019
github-actions commentedon May 1, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.