rectorphp/rector · error · ShouldNotHappenException
"%s" is deprecated as it produces too many false positives.
Error message
"%s" is deprecated as it produces too many false positives. Add the type manually where needed instead
What it means
Rector\TypeDeclaration\Rector\ClassMethod\StrictStringParamConcatRector is deprecated: refactor() throws Rector\Exception\ShouldNotHappenException on the first ClassMethod, Function_ or Closure node. The rule added `string` parameter types to parameters that get concatenated with strings, but that heuristic produced too many false positives (non-string values concatenated via __toString, mixed input, casts). The rule targets PHP 7.0+ (PhpVersionFeature::SCALAR_TYPES).
Source
Thrown at rules/TypeDeclaration/Rector/ClassMethod/StrictStringParamConcatRector.php:60
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes(): array
{
return [ClassMethod::class, Function_::class, Closure::class];
}
public function provideMinPhpVersion(): int
{
return PhpVersionFeature::SCALAR_TYPES;
}
/**
* @param ClassMethod|Function_|Closure $node
*/
public function refactor(Node $node): ?Node
{
throw new ShouldNotHappenException(sprintf('"%s" is deprecated as it produces too many false positives. Add the type manually where needed instead', self::class));
}
}
View on GitHub (pinned to 408fcb0ff1)
Solutions
- Remove StrictStringParamConcatRector from rector.php.
- Add `string` parameter types manually where the value really is always a string, verifying with PHPStan first.
- Use phpstan level-driven type coverage reports instead of the concatenation heuristic.
Example fix
// before (rector.php)
->withRules([StrictStringParamConcatRector::class])
// after (rector.php) - removed; add types by hand
// before // after
function greet($name, $suffix) function greet(string $name, string $suffix)
{
return $name . $suffix;
} Defensive patterns
Strategy: validation
Validate before calling
use Rector\TypeDeclaration\Rector\ClassMethod\StrictStringParamConcatRector;
$rules = [/* your list */ StrictStringParamConcatRector::class];
if (in_array(StrictStringParamConcatRector::class, $rules, true)) {
throw new InvalidArgumentException('Rule deprecated due to false positives; add string types manually');
} Try / catch
try {
exit($rectorApplication->run());
} catch (\Rector\Exception\ShouldNotHappenException $e) {
if (str_contains($e->getMessage(), 'StrictStringParamConcatRector')) {
fwrite(STDERR, 'Remove the rule; derive parameter types from PHPStan knowledge, not concatenation.' . PHP_EOL);
exit(1);
}
throw $e;
} Prevention
- Add parameter types guided by PHPStan reports on call sites rather than by usage heuristics.
- Watch for Stringable/int values in concatenating code before typing a param as string.
- Prune deprecated TypeDeclaration rules from rector.php whenever rector is updated.
When it happens
Trigger: The rule is still present in rector.php and the analyzed code contains any closure, function or method; refactor() throws on the first visited node, before any type analysis happens.
Common situations: Old 'strict types' rector configs; CI failing immediately after a rector upgrade; codebases where the rule previously mis-typed parameters that receive int/float/Stringable values.
Related errors
- "%s" rule is deprecated, as too niche and of little practica
- "%s" is deprecated, as it copies docblock from another metho
- "%s" rule is deprecated, as turning a docblock type into a r
- "%s" rule is deprecated, as risky. The "??" and "?:" operato
- "%s" is deprecated as depends on context and personal prefer
AI-assisted analysis of rectorphp/rector@408fcb0ff1 (2026-08-21).
Data as JSON: /api/errors/533f1a73de67af43.
Report an issue: GitHub.