rectorphp/rector · error · ShouldNotHappenException
"%s" is deprecated as risky change with little value. Use ma
Error message
"%s" is deprecated as risky change with little value. Use manually or custom rule where needed instead
What it means
This ShouldNotHappenException is thrown when the deprecated StaticCallOnNonStaticToInstanceCallRector actually runs. The rule used to rewrite `ClassName::nonStaticMethod()` calls into instance calls, but that was deemed a risky change with little value; the class remains (implementing DeprecatedInterface) only so stale configs fail loudly. Its refactor() throws unconditionally on the first StaticCall node visited.
Source
Thrown at rules/Php70/Rector/StaticCall/StaticCallOnNonStaticToInstanceCallRector.php:72
return (new Something)->doWork();
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes(): array
{
return [StaticCall::class];
}
/**
* @param StaticCall $node
*/
public function refactor(Node $node): ?Node
{
throw new ShouldNotHappenException(sprintf('"%s" is deprecated as risky change with little value. Use manually or custom rule where needed instead', self::class));
}
}
View on GitHub (pinned to 408fcb0ff1)
Solutions
- Remove the `StaticCallOnNonStaticToInstanceCallRector::class` registration from rector.php/rector.yml and re-run.
- Audit the config for other deprecated rules (EarlyReturn rules, other removed Php70 rules) and remove them in the same pass.
- If you need that rewrite, do it manually or in a project-local custom rule — as the exception message itself advises.
- Short-term stopgap: pin the last Rector version where this rule still performed the transformation.
Example fix
// before - rector.php $rectorConfig->rule(\Rector\Php70\Rector\StaticCall\StaticCallOnNonStaticToInstanceCallRector::class); // after - registration removed; convert static-call-on-instance manually // $obj = new ClassName(); $obj->method();
Defensive patterns
Strategy: validation
Validate before calling
$config = file_get_contents('rector.php');
if (strpos($config, 'StaticCallOnNonStaticToInstanceCallRector') !== false) {
exit("Remove deprecated StaticCallOnNonStaticToInstanceCallRector from rector.php before running rector.\n");
} Prevention
- Prefer version level sets over individually registered Php70 rules so deprecated rules disappear on upgrade.
- On every rector major upgrade, grep rector.php for rule classes flagged DeprecatedInterface in the changelog and delete them.
- Keep a smoke-test directory and run rector against it right after upgrading, so stale registrations fail in seconds, not mid-CI.
When it happens
Trigger: Running `rector process` with a config that still registers `\Rector\Php70\Rector\StaticCall\StaticCallOnNonStaticToInstanceCallRector::class` (or an old Php70 rule list that included it). getNodeTypes() returns [StaticCall::class], so the exception fires as soon as Rector visits any static call in the analyzed code — no particular PHP version of the target code matters beyond the rule being loaded.
Common situations: Upgrading rector/rector across major versions while keeping an enumerated rule list from the PHP 5.6-to-7 migration era; inheriting a config that itemized Php70 rules; CI breaking after a routine `composer update` because the rule now throws instead of refactoring.
Related errors
- "%s" rule is deprecated, as inverting nested ifs to early re
- "%s" rule is deprecated, as splitting a single condition int
- "%s" rule is deprecated, as splitting a single return into m
- "%s" rule is deprecated, as turning a docblock type into a r
- "%s" rule is deprecated, as risky. The "??" and "?:" operato
AI-assisted analysis of rectorphp/rector@408fcb0ff1 (2026-08-21).
Data as JSON: /api/errors/34be8be9d164cf9b.
Report an issue: GitHub.