Add RectorCheaperGuardsFirstRule to rector set - #280
Merged
Conversation
Ported from rector-src: flags a cheap early-return guard (isName, count, in_array) placed after an expensive analysis call (getType, isObjectType, ...) inside a Rector rule, where the cheap guard could bail out first and skip the costly analysis. Claude-Session: https://claude.ai/code/session_01Na4eYvNqa2pdhZrBXbegrv
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.
Adds
RectorCheaperGuardsFirstRuleunder the rector rule set.Inside a Rector rule, a cheap early-return guard (
isName(),count(),in_array()) that does not depend on an expensive analysis call (getType(),isObjectType(),createFromNodeOrEmpty(), ...) should run before that call, so non-matching nodes bail out before paying for the costly analysis. The rule flags cases where a cheap, independent guard sits after such a call and could be hoisted.Ported from
rector/rector-srcinternal PHPStan tooling, as it is useful for anyone writing custom Rector rules.Registered in
config/rector-rules.neon, with test fixtures covering the reported case plus two skip cases (already cheap-first, and a guard dependent on the analysis result).