[Rector] Add NoScopeFetchBeforeCheapGuardRule and NarrowReturnToUnionParamRule to rector set by TomasVotruba · Pull Request #375 · symplify/phpstan-rules · GitHub
Skip to content

[Rector] Add NoScopeFetchBeforeCheapGuardRule and NarrowReturnToUnionParamRule to rector set - #375

Merged
TomasVotruba merged 3 commits into
mainfrom
move-rector-perf-rules
Oct 16, 2026
Merged

TomasVotruba merged 3 commits into
mainfrom
move-rector-perf-rules

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Move two performance-oriented Rector rules into the shared rector set, so every rector package picks them up:

  • NoScopeFetchBeforeCheapGuardRule - flags ScopeFetcher::fetch() called right before a cheap guard that does not use the scope; the guard should run first so most nodes bail out before scope resolution.
  • NarrowReturnToUnionParamRule - flags a method that takes a class-type union param (A|B) but declares a broader single return type (e.g. their shared parent Node) and returns that very param; the return type should be the explicit union.

Both were living in rector-src/utils. They depend only on PhpParser/PHPStan plus Rector\PHPStan\ScopeFetcher, so they are reusable across all rector packages.

Registered in config/rector-rules.neon, tests under tests/Rules/Rector.

@TomasVotruba
TomasVotruba merged commit bfba4cb into main Oct 16, 2026
9 checks passed
@TomasVotruba
TomasVotruba deleted the move-rector-perf-rules branch October 16, 2026 09:54
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