Skip to content
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

Rewrite multi param isset() to and-chain #2709

Merged
merged 6 commits into from
Nov 2, 2023

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Nov 2, 2023

motivation: ease impl of #2657 by moving the expr-var loop before the context true/false branches which simplifies the branch cases

closes phpstan/phpstan#8366
closes phpstan/phpstan#10064

}

$types = null;
$tmpVars = [$issetExpr];
Copy link
Contributor Author

@staabm staabm Nov 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to rename this var, because the previous $var variable after this PR is no longer within a foreach and therefore PHPStan would otherwise report a overlap with the foreach-var below

(no logic change contained otherwise in this block)


$specifiedTypes = new SpecifiedTypes();
// rewrite multi param isset() to and-chained single param isset()
if (count($expr->vars) > 1) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the actual change is here.

Implemented the idea expressed in phpstan/phpstan#8366 (comment)

@staabm staabm marked this pull request as ready for review November 2, 2023 14:47
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@staabm
Copy link
Contributor Author

staabm commented Nov 2, 2023

ahh, let me add a regression test for phpstan/phpstan#10064

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent idea, thank you

): void {

if (isset($untilDate, $count)) {
throw new \InvalidArgumentException('Too much params, choose between until and count.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional assertType calls inside this condition would be great

@ondrejmirtes ondrejmirtes merged commit b4c4497 into phpstan:1.10.x Nov 2, 2023
413 of 417 checks passed
@ondrejmirtes
Copy link
Member

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants