phpstan / phpstan-symfony

Symfony extension for PHPStan
MIT License
698 stars 89 forks source link

wrong asumption about `InputInterface::getArgument()` return type in `interact()` #396

Closed nikophil closed 2 months ago

nikophil commented 3 months ago

Hello,

since this PR, if the config symfony.consoleApplicationLoader is not provided, PHPStan will always consider that every call to $input->getArgument() inside the method interfact() will return null.

Maybe some guard condition should be added gefore adding NullType.

I'm willing to fix this if you think it is relevant

ondrejmirtes commented 3 months ago

/cc @VincentLanglet

VincentLanglet commented 3 months ago

PHPStan will always consider that every call to $input->getArgument() inside the method interfact() will return null.

Maybe some guard condition should be added gefore adding NullType.

I made some new tries and

$this->addArgument('task', InputArgument::REQUIRED); // Possibly null in interact
$this->addArgument('task', InputArgument::REQUIRED | InputArgument::ARRAY); // [] in interact
$this->addArgument('task', InputArgument::REQUIRED, default: 'foo'); // Not possible
$this->addArgument('task', InputArgument::OPTIONAL); // Possibly null in interact
$this->addArgument('task', InputArgument::OPTIONAL, default: 'foo'); // Not null in interact

And also, indeed, we need to add Null only if some types were already inferred.

I opened https://github.com/phpstan/phpstan-symfony/pull/397

ondrejmirtes commented 3 months ago

Please test 1.4.4 https://github.com/phpstan/phpstan-symfony/releases/tag/1.4.4 to see whether it fixes your problem.

nikophil commented 2 months ago

problem fixed :heavy_check_mark:

thanks!

github-actions[bot] commented 1 month ago

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.