Skip to content

Run cheap guards before expensive analysis calls - #519

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

Run cheap guards before expensive analysis calls#519
TomasVotruba merged 1 commit into
mainfrom
cheaper-guards-first-order

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

symplify/phpstan-rules 14.13.0 adds RectorCheaperGuardsFirstRule, which flags a cheap early-return guard (isName(), isNames(), isFirstClassCallable(), ...) that runs after an expensive analysis call (getType(), isObjectType(), ...) when the cheap guard does not depend on the expensive call's result.

This reorders 5 rules so the cheap, independent guards run first and short-circuit before the expensive type resolution:

  • Dbal211 ExtractArrayArgOnQueryBuilderSelectRector
  • Dbal36 MigrateQueryBuilderResetQueryPartRector
  • Dbal40 ChangeCompositeExpressionAddMultipleWithWithRector
  • Orm28 IterateToToIterableRector
  • Orm30 SetParametersArrayToCollectionRector

Behavior-preserving: all guards only return null, so their relative order does not change the result. PHPStan, ECS, and the affected rule tests pass.

Move cheap early-return guards (isName, isNames, isFirstClassCallable)
before expensive type analysis calls (getType, isObjectType) in 5 rules.

Claude-Session: https://claude.ai/code/session_01Na4eYvNqa2pdhZrBXbegrv
@TomasVotruba
TomasVotruba merged commit b997d3f 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