{"record":{"id":"14876d64e70d1059","repo":"rectorphp/rector","slug":"s-rule-is-deprecated-as-turning-a-docblock-typ","errorCode":null,"errorMessage":"\"%s\" rule is deprecated, as turning a docblock type into a runtime assert is risky and academic. Write a custom rule if the project needs it","messagePattern":"\"(.+?)\" rule is deprecated, as turning a docblock type into a runtime assert is risky and academic\\. Write a custom rule if the project needs it","errorType":"exception","errorClass":"ShouldNotHappenException","httpStatus":null,"severity":"error","filePath":"rules/Assert/Rector/ClassMethod/AddAssertArrayFromClassMethodDocblockRector.php","lineNumber":61,"sourceCode":"     */\n    public function run(array $items)\n    {\n        Assert::allInteger($items);\n    }\n}\nCODE_SAMPLE\n, ['Webmozart\\Assert\\Assert'])]);\n    }\n    public function getNodeTypes(): array\n    {\n        return [ClassMethod::class];\n    }\n    /**\n     * @param ClassMethod $node\n     */\n    public function refactor(Node $node): ?ClassMethod\n    {\n        throw new ShouldNotHappenException(sprintf('\"%s\" rule is deprecated, as turning a docblock type into a runtime assert is risky and academic. Write a custom rule if the project needs it', self::class));\n    }\n    /**\n     * @param array<string> $configuration\n     */\n    public function configure(array $configuration): void\n    {\n    }\n}\n","sourceCodeStart":43,"sourceCodeEnd":70,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/rules/Assert/Rector/ClassMethod/AddAssertArrayFromClassMethodDocblockRector.php#L43-L70","documentation":"AddAssertArrayFromClassMethodDocblockRector used to generate runtime Assert::allInteger()-style calls from @param array<int> docblocks on class methods. The rule is deprecated because converting a static docblock type into a runtime assertion is risky (docblocks are often incomplete) and of academic value only, so its refactor() now unconditionally throws ShouldNotHappenException. Hitting this error means your configuration still registers this dead rule: the class exists only so old configs can be discovered and flagged, it performs no transformation. The empty configure() body also means passing configuration no longer suppresses the throw.","triggerScenarios":"Registering rules/Assert/Rector/ClassMethod/AddAssertArrayFromClassMethodDocblockRector.php in rector.php (directly or via a set) and running vendor/bin/rector process or dry-run over any file that contains a ClassMethod node. The throw fires from refactor() at rules/Assert/Rector/ClassMethod/AddAssertArrayFromClassMethodDocblockRector.php:61 as soon as Rector visits the first matching node.","commonSituations":"Upgrading rector/rector-prefixed to a version where the Assert docblock rules were gutted, while rector.php still lists the rule in ->withRules([...]) or imports an old custom set file. Copying a rule list from an old blog post or another project's config also triggers it. Calling ->configure([...]) on the rule does not help — the method is now empty.","solutions":["Remove AddAssertArrayFromClassMethodDocblockRector::class from rector.php (and from any imported custom set), then re-run vendor/bin/rector dry-run","If you genuinely need docblock-driven runtime asserts, write a project-specific custom rule implementing Rector\\Rector\\AbstractRector and register it locally","Prefer verifying array shapes statically with PHPStan instead of injecting runtime asserts","If the rule came from a bundled set, drop that set import and pick the rules you still want individually"],"exampleFix":"// before (rector.php)\nreturn RectorConfig::configure()\n    ->withRules([\n        AddAssertArrayFromClassMethodDocblockRector::class,\n    ]);\n\n// after\nreturn RectorConfig::configure();\n// need runtime asserts? enforce @param array<int> shapes in PHPStan instead, or write a custom rule","handlingStrategy":"validation","validationCode":"// before running rector, verify no deprecated rule is registered\n$deprecated = ['AddAssertArrayFromClassMethodDocblockRector'];\nforeach (glob(__DIR__ . '/rector*.php') as $config) {\n    $src = file_get_contents($config);\n    foreach ($deprecated as $rule) {\n        if (str_contains($src, $rule)) {\n            fwrite(STDERR, \"Remove deprecated rule {$rule} from {$config}\\n\");\n            exit(1);\n        }\n    }\n}\n// safe to run: vendor/bin/rector dry-run","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remove deprecated rules from rector.php before upgrading rector/rector-prefixed","Run vendor/bin/rector dry-run on a single small path first so guard throws surface cheaply","Keep custom rules in your own namespace so bundled-rule deprecations never break your config","Read the Rector UPGRADING notes for each major version and prune your rule list accordingly"],"tags":["rector","php","deprecated-rule","assert","docblock"],"backgroundTag":"rector-deprecated-rule","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}