Skip to content

Report implicit mixed in boolean conditions on level 10 - #340

Open
mkantautas wants to merge 1 commit into
phpstan:2.1.xfrom
mkantautas:fix/implicit-mixed-in-conditions
Open

mkantautas wants to merge 1 commit into
phpstan:2.1.xfrom
mkantautas:fix/implicit-mixed-in-conditions

Conversation

@mkantautas

Copy link
Copy Markdown

Fixes #253
Fixes #289

BooleanRuleHelper::passesAsBoolean() returned early for every MixedType, so implicit mixed passed regardless of checkImplicitMixed. On level 10, conditions on untyped parameters or on values of untyped arrays were never reported, while the same code with array<mixed> was.

Following option 3 from #253, explicit mixed is still reported on every level, and implicit mixed now goes through RuleLevelHelper::findTypeToCheck(), so it is reported only when checkImplicitMixed is enabled (level 10). ErrorType keeps passing as before, so an expression that already has an error (unknown function, undefined variable) does not get a second one.

This covers every rule using the helper: if, elseif, ternary, !, &&, ||, and the loop conditions when they are enabled. Levels 0–9 are unchanged. Level 10 users get new *.condNotBoolean errors for these conditions; the change is not behind bleeding edge.

Tests: tests/Levels/data/onlyBooleans.php gets the #253 and #289 cases plus unknown-function and undefined-variable controls. The new onlyBooleans-10.json fails on 2.1.x. make lint, make tests, make phpstan and make cs pass, and tests and PHPStan pass on PHP 7.4–8.5 with lowest and highest dependencies.

@VincentLanglet
VincentLanglet requested a review from staabm October 23, 2026 07:04
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