Fix OrChainIdenticalComparisonToInArrayRule#5881
Merged
Merged
Conversation
VincentLanglet
approved these changes
Jun 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
why is this change required?
The original line was
self::isSubjectNode($comparison->left) && !self::isSubjectNode($comparison->left)— a self-contradictoryX && !Xthat is alwaysfalse. That first branch never executed, so the rule could only ever match the second branch (subject on the left, value on the right, e.g.$var === 'foo'). Yoda-style comparisons where the literal is on the left ('foo' === $var) fell through and returnednull, so those chains were silently never reported or fixed. Changing the second check to$comparison->rightmakes the first branch correctly handle "value on the left".Added a failing-without-the-fix test
tests/PHPStan/Build/data/or-chain-identical-comparison.php: two new yoda-style chains —'foo' === $var || 'bar' === $varand a mixed'foo' === $var || $var === 'bar'....php.fixed: their expectedin_array()rewrites.OrChainIdenticalComparisonToInArrayRuleTest: added the two expected errors at lines 21 and 25.Verification
testRuleandtestFixpass.->leftversion and confirmed both tests fail (the line-21/25 errors are missing and the fixer leaves the yoda chains unchanged), then restored the fix.make phpstan: green.extracted from #5880