[CodeQuality] Skip short-circuit dependent values on RepeatedAndNotEqualToNotInArrayRector and RepeatedOrEqualToInArrayRector - #8516
Merged
TomasVotruba merged 1 commit intoSep 23, 2026
Conversation
…ualToNotInArrayRector and RepeatedOrEqualToInArrayRector
A repeated null check where later operands rely on earlier ones:
null !== $locale && null !== $translations && null !== $translations->getTranslation($locale)
became
!in_array(null, [$locale, $translations, $translations->getTranslation($locale)], true)
The array literal evaluates every item up front, while && stops at the
first failing compare, so getTranslation() now runs on a null
$translations, or with a null $locale it does not accept. The || variant
in RepeatedOrEqualToInArrayRector had the same issue.
Both rules build the array in InArrayFromRepeatedCompareFactory, which now
only accepts values that are safe to evaluate eagerly: plain variables,
scalars, constants, class constants and constant arrays. Calls, property
and array fetches keep the chain as is.
Member
|
Thanks |
guillaume-sainthillier
deleted the
skip-short-circuit-dependent-in-array
branch
September 23, 2026 16:42
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.
RepeatedAndNotEqualToNotInArrayRectorrewrote a chain of null checks where later operands depend on earlier ones:into
The array literal evaluates every item up front, while
&&stops at the first failing compare.getTranslation()now runs on a null$translationsand, with a null$locale, receives an argument itsstringparam does not accept. A nullsafe?->would only cover the first case, so the chain has to stay as is.RepeatedOrEqualToInArrayRectorhad the same issue with||.Both rules build the array in
InArrayFromRepeatedCompareFactory, which now only accepts values that are safe to evaluate eagerly: plain variables, plus whatExprAnalyzer::isDynamicExpr()already treats as static (scalars, constants, class constants, constant arrays). Method calls, property and array fetches, and$$namekeep the original chain.The compared expression is not restricted: the chain always evaluates it at least once and
in_array()evaluates it exactly once.Fixtures, for each rule:
skip_short_circuit_dependent_call.php.inc: the case above stays unchangedyoda_null_on_variables.php.inc:null !== $a && null !== $b && null !== $cstill becomes!in_array(null, [$a, $b, $c], true)