Skip to content

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

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

Closed
nikophil opened this issue Jun 6, 2024 · 5 comments

Comments

@nikophil
Copy link

nikophil commented Jun 6, 2024

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
Copy link
Member

/cc @VincentLanglet

@VincentLanglet
Copy link
Contributor

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 #397

@ondrejmirtes
Copy link
Member

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

@nikophil
Copy link
Author

problem fixed ✔️

thanks!

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants