{"record":{"id":"7fec0c0e6130a71e","repo":"rectorphp/rector","slug":"s-is-deprecated-as-it-copies-docblock-from-ano","errorCode":null,"errorMessage":"\"%s\" is deprecated, as it copies docblock from another method call that can be incorrect or outdated","messagePattern":"\"(.+?)\" is deprecated, as it copies docblock from another method call that can be incorrect or outdated","errorType":"exception","errorClass":"ShouldNotHappenException","httpStatus":null,"severity":"error","filePath":"rules/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockFromMethodCallDocblockRector.php","lineNumber":77,"sourceCode":"        // ...\n    }\n}\nCODE_SAMPLE\n)]);\n    }\n    /**\n     * @return array<class-string<Node>>\n     */\n    public function getNodeTypes(): array\n    {\n        return [ClassMethod::class];\n    }\n    /**\n     * @param ClassMethod $node\n     */\n    public function refactor(Node $node): ?Node\n    {\n        throw new ShouldNotHappenException(sprintf('\"%s\" is deprecated, as it copies docblock from another method call that can be incorrect or outdated', self::class));\n    }\n}\n","sourceCodeStart":59,"sourceCodeEnd":80,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/rules/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockFromMethodCallDocblockRector.php#L59-L80","documentation":"Rector\\TypeDeclarationDocblocks\\Rector\\ClassMethod\\AddReturnDocblockFromMethodCallDocblockRector is deprecated: refactor() throws Rector\\Exception\\ShouldNotHappenException on the first ClassMethod node. The rule copied the @return docblock from another method call (e.g. the create() call inside the body) onto the enclosing method, but a copied docblock can be incorrect for the wrapper or become outdated when the inner method changes.","triggerScenarios":"The rule is still listed in a TypeDeclarationDocblocks rule list and rector visits any class method; refactor() throws on the first ClassMethod match.","commonSituations":"Static-analysis coverage pushes that added docblocks everywhere; CI failing at the first factory-style method after a rector upgrade; docblocks drifting out of sync with the copied source method.","solutions":["Remove AddReturnDocblockFromMethodCallDocblockRector from rector.php.","Add the @return docblock manually where the wrapper's return type is genuinely the same, and keep it in sync on changes.","Better: add a native return type or delegate the type via PHPStan generics instead of copying docblocks."],"exampleFix":"// before (rector.php)\n->withRules([AddReturnDocblockFromMethodCallRector::class])\n\n// after (rector.php) - removed; write by hand\n\n/**\n * @return array<int, Item>\n */\npublic function createAll(): array","handlingStrategy":"validation","validationCode":"use Rector\\TypeDeclarationDocblocks\\Rector\\ClassMethod\\AddReturnDocblockFromMethodCallDocblockRector;\n\n$rules = [/* your list */ AddReturnDocblockFromMethodCallDocblockRector::class];\nif (in_array(AddReturnDocblockFromMethodCallDocblockRector::class, $rules, true)) {\n    throw new InvalidArgumentException('Rule deprecated; do not copy docblocks between methods automatically');\n}","typeGuard":null,"tryCatchPattern":"try {\n    exit($rectorApplication->run());\n} catch (\\Rector\\Exception\\ShouldNotHappenException $e) {\n    if (str_contains($e->getMessage(), 'AddReturnDocblockFromMethodCallDocblockRector')) {\n        fwrite(STDERR, 'Remove the rule; copied docblocks drift from the inner method.' . PHP_EOL);\n        exit(1);\n    }\n    throw $e;\n}","preventionTips":["Give wrappers their own native return type or generics annotation instead of copying the inner method's docblock.","When delegating types, rely on PHPStan's generics (@template/@T) rather than duplicated text.","Remove deprecated docblock rules from rector.php during upgrade sweeps."],"tags":["rector","php","docblock","return-type","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"}