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

  1. Remove the `StaticCallOnNonStaticToInstanceCallRector::class` registration from rector.php/rector.yml and re-run.
  2. Audit the config for other deprecated rules (EarlyReturn rules, other removed Php70 rules) and remove them in the same pass.
  3. If you need that rewrite, do it manually or in a project-local custom rule — as the exception message itself advises.
  4. 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

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


AI-assisted analysis of rectorphp/rector@408fcb0ff1 (2026-08-21). Data as JSON: /api/errors/34be8be9d164cf9b. Report an issue: GitHub.