Skip to content

Run cheap guards before expensive analysis calls - #1062

Merged
TomasVotruba merged 1 commit into
mainfrom
cheaper-guards-first-order
Aug 29, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
cheaper-guards-first-order

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

The new RectorCheaperGuardsFirstRule in symplify/phpstan-rules 14.13.0 flags a cheap early-return guard (isName(), isNames(), count(), instanceof, ...) that sits after an expensive analysis call (getType(), isObjectType(), ...) inside a Rector rule, when the cheap guard does not depend on the expensive call result.

This reorders 7 such rules so non-matching nodes bail out before the costly type analysis runs. Behavior is unchanged; only guard order shifts.

Rules updated:

  • AssertSameResponseCodeWithDebugContentsRector
  • AddViolationToBuildViolationRector
  • ConsoleExceptionToErrorEventConstantRector
  • ContainerBuilderCompileEnvArgumentRector
  • VarDumperTestTraitMethodArgsRector
  • AuthorizationCheckerIsGrantedExtractorRector
  • RenameCopyOnWindowsOptionToFollowSymlinksRector

Reorder early-return guards in 7 Rector rules so cheap checks
(isName/isNames/count/instanceof) bail out before costly type
analysis (getType/isObjectType). Fixes new RectorCheaperGuardsFirstRule
from symplify/phpstan-rules 14.13.0.

Claude-Session: https://claude.ai/code/session_01Na4eYvNqa2pdhZrBXbegrv
@TomasVotruba
TomasVotruba merged commit 2529e11 into main Aug 29, 2026
7 checks passed
@TomasVotruba
TomasVotruba deleted the cheaper-guards-first-order branch August 29, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant