{"record":{"id":"3058cd8a61454c67","repo":"rectorphp/rector","slug":"s-rule-is-deprecated-as-too-niche-and-of-littl","errorCode":null,"errorMessage":"\"%s\" rule is deprecated, as too niche and of little practical value. The item type is already known from the inline closure return type","messagePattern":"\"(.+?)\" rule is deprecated, as too niche and of little practical value\\. The item type is already known from the inline closure return type","errorType":"exception","errorClass":"ShouldNotHappenException","httpStatus":null,"severity":"error","filePath":"rules/TypeDeclaration/Rector/ClassMethod/AddReturnArrayDocblockBasedOnArrayMapRector.php","lineNumber":58,"sourceCode":"        return array_map(function ($item): int {\n            return $item->id;\n        }, $items);\n    }\n}\nCODE_SAMPLE\n)]);\n    }\n    public function getNodeTypes(): array\n    {\n        return [ClassMethod::class, Function_::class];\n    }\n    /**\n     * @param ClassMethod|Function_ $node\n     * @return null|\\PhpParser\\Node\\Stmt\\Function_|\\PhpParser\\Node\\Stmt\\ClassMethod\n     */\n    public function refactor(Node $node)\n    {\n        throw new ShouldNotHappenException(sprintf('\"%s\" rule is deprecated, as too niche and of little practical value. The item type is already known from the inline closure return type', self::class));\n    }\n}\n","sourceCodeStart":40,"sourceCodeEnd":61,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/rules/TypeDeclaration/Rector/ClassMethod/AddReturnArrayDocblockBasedOnArrayMapRector.php#L40-L61","documentation":"Rector\\TypeDeclaration\\Rector\\ClassMethod\\AddReturnArrayDocblockBasedOnArrayMapRector is deprecated: refactor() throws Rector\\Exception\\ShouldNotHappenException on the first ClassMethod or Function_ node. The rule added an @return array<...> docblock inferred from an array_map() call in the body, but the item type is already visible in the inline closure's return type, so the generated docblock is redundant noise of little practical value.","triggerScenarios":"The rule is still listed in a TypeDeclaration rule list in rector.php and rector visits any method or function; refactor() throws on the first ClassMethod/Function_ match.","commonSituations":"Bulk-enabling every TypeDeclaration rule for 'better types'; CI failing on the first analyzed method after a rector upgrade; configs shared between repositories that still carry the rule name.","solutions":["Remove AddReturnArrayDocblockBasedOnArrayMapRector from rector.php.","Where the item type genuinely helps (public APIs), write the @return docblock manually.","Consider adding native return types or closure parameter types instead of relying on generated docblocks."],"exampleFix":"// before (rector.php)\n->withRules([AddReturnArrayDocblockBasedOnArrayMapRector::class])\n\n// after (rector.php) - removed; add by hand where useful\n\n// manual, optional:\n/**\n * @return array<int, UserDto>\n */\npublic function mapUsers(array $rows): array","handlingStrategy":"validation","validationCode":"use Rector\\TypeDeclaration\\Rector\\ClassMethod\\AddReturnArrayDocblockBasedOnArrayMapRector;\n\n$rules = [/* your list */ AddReturnArrayDocblockBasedOnArrayMapRector::class];\nif (in_array(AddReturnArrayDocblockBasedOnArrayMapRector::class, $rules, true)) {\n    throw new InvalidArgumentException('Rule deprecated; the item type is already visible in the array_map closure');\n}","typeGuard":null,"tryCatchPattern":"try {\n    exit($rectorApplication->run());\n} catch (\\Rector\\Exception\\ShouldNotHappenException $e) {\n    if (str_contains($e->getMessage(), 'AddReturnArrayDocblockBasedOnArrayMapRector')) {\n        fwrite(STDERR, 'Remove the rule; add @return docblocks manually where they add value.' . PHP_EOL);\n        exit(1);\n    }\n    throw $e;\n}","preventionTips":["Curate the TypeDeclaration rule list instead of enabling the whole set; several members are now deprecated stubs.","Write @return docblocks for public APIs in the same PR that introduces the code.","Check rector release notes for TypeDeclaration removals before upgrading shared configs."],"tags":["rector","php","docblock","array-map","type-declaration","deprecated-rule"],"backgroundTag":"deprecated-api-invoked","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}