Skip to content

Add RectorCheaperGuardsFirstRule to rector set - #280

Merged
TomasVotruba merged 1 commit into
mainfrom
add-rector-cheaper-guards-first-rule
Aug 29, 2026
Merged

Add RectorCheaperGuardsFirstRule to rector set#280
TomasVotruba merged 1 commit into
mainfrom
add-rector-cheaper-guards-first-rule

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Adds RectorCheaperGuardsFirstRule under 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-src internal 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).

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
@TomasVotruba
TomasVotruba merged commit 2439f24 into main Aug 29, 2026
8 checks passed
@TomasVotruba
TomasVotruba deleted the add-rector-cheaper-guards-first-rule branch August 29, 2026 17:17
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.

1 participant