You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DirectInstanceOverMockArgRector crashes with "Scope not available" on named arg after spread in new #9869
PHPStan assigns no scope to the arguments of a new expression that mixes an
unpacked spread with a named argument filling a required constructor
parameter — it cannot reorder the arguments, so it never descends into them.
The rule then throws:
System error: "Scope not available on "PhpParser\Node\Expr\MethodCall" node.
Fix scope refresh on changed nodes first"
Two things make this painful:
The file does not have to be a test. The TestCase check sits after the
scope fetch, so the crash happens in ordinary application code.
The rule ships in the phpunit-code-quality prepared set, so ->withPreparedSets(phpunitCodeQuality: true) makes any project with this
argument shape fail its whole Rector run.
The rule only rewrites mocks of Symfony's Request / RequestStack, so it had
nothing to do with the code it crashed on.
Minimal PHP Code Causing Issue
Reproduced locally with only DirectInstanceOverMockArgRector enabled:
Move the scope fetch after the cheap guards, or make it tolerate a missing
scope. The rule needs the scope only to confirm the class is a TestCase;
with no scope it can return null.
More generally, ScopeFetcher::fetch() throwing on nodes PHPStan never
visited turns a PHPStan limitation into a hard failure of the whole run.
A nullable ScopeFetcher::fetchOrNull() for rules that can degrade
gracefully would stop one rule from taking down a full-tree run.
Activity
TomasVotruba commentedon Aug 27, 2026
Thank you for your report!
We'll need an isolated failing demo link from: http://getrector.com/demo,
that way we can reproduce the bug.
billypoke commentedon Aug 27, 2026
@TomasVotruba sorry! Here's a repro - https://getrector.com/demo/1eee4ce2-1b47-4d83-a812-a38e5dce2519
TomasVotruba commentedon Aug 27, 2026
Awesome, thank you 👍
Fix incoming rectorphp/rector-phpunit#776