Skip to content

Conversation

VincentLanglet
Copy link
Contributor

Might be enough to close #259

I tried to implement the same thing for For_.

But the issue I encounter in

for ($i = 0; $i; $i++) {}

is that $i is considered as a MixedType, which is non explicit, so BooleanHelper::passesAsBoolean always return true.

So i'm unsure the rule is doable for for loops.

@VincentLanglet
Copy link
Contributor Author

Friendly ping @ondrejmirtes if you find some time 👍

rules.neon Outdated
PHPStan\Rules\BooleansInConditions\BooleanInBooleanOrRule:
phpstan.rules.rule: %strictRules.booleansInConditions%
PHPStan\Rules\BooleansInConditions\BooleanInDoWhileConditionRule:
phpstan.rules.rule: %strictRules.booleansInConditions%
Copy link
Member

Choose a reason for hiding this comment

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

This is a new rule. It has to be part of bleeding edge. See how this was done in 1.x:

disallowedLooseComparison: [%strictRules.allRules%, %featureToggles.bleedingEdge%]

This also means this needs a new config parameter. Something like booleansInLoopConditions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, should be ok now

@ondrejmirtes ondrejmirtes merged commit 3e139cb into phpstan:2.0.x Mar 18, 2025
31 checks passed
@ondrejmirtes
Copy link
Member

Perfect, 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

Development

Successfully merging this pull request may close these issues.

Check BooleanInCondition for while and for loop

2 participants