{"record":{"id":"b6ab725a740b581c","repo":"rectorphp/rector","slug":"s-rule-is-deprecated-as-the-array-shape-guesse","errorCode":null,"errorMessage":"\"%s\" rule is deprecated, as the array shape guessed from conditional assigns is vague and unreliable. Add the @return docblock manually instead","messagePattern":"\"(.+?)\" rule is deprecated, as the array shape guessed from conditional assigns is vague and unreliable\\. Add the @return docblock manually instead","errorType":"exception","errorClass":"ShouldNotHappenException","httpStatus":null,"severity":"error","filePath":"rules/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockForDimFetchArrayFromAssignsRector.php","lineNumber":72,"sourceCode":"            $items['another_key'] = 'another_value';\n        }\n\n        return $items;\n    }\n}\nCODE_SAMPLE\n)]);\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 the array shape guessed from conditional assigns is vague and unreliable. Add the @return docblock manually instead', self::class));\n    }\n}\n","sourceCodeStart":54,"sourceCodeEnd":75,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/rules/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockForDimFetchArrayFromAssignsRector.php#L54-L75","documentation":"Rector\\TypeDeclarationDocblocks\\Rector\\ClassMethod\\AddReturnDocblockForDimFetchArrayFromAssignsRector is deprecated: refactor() throws Rector\\Exception\\ShouldNotHappenException on the first ClassMethod node. The rule reconstructed a @return array shape docblock from conditional dimension-fetch assignments ($row['key'] = ...), but an array shape guessed from assignments is vague and easily wrong once a branch is added or reordered.","triggerScenarios":"The rule is still referenced in a TypeDeclarationDocblocks rule list and rector visits any class method; refactor() throws on the first ClassMethod match.","commonSituations":"Configs aiming for full PHPStan array-shape coverage; CI failing on the first method after a rector upgrade; legacy experiments where generated shapes later disagreed with reality.","solutions":["Remove AddReturnDocblockForDimFetchArrayFromAssignsRector from rector.php.","Declare the array shape manually with a @return docblock (or a named value object/array shape type) where it is stable and useful.","Where the shape keeps evolving, prefer a small DTO class over a docblock shape."],"exampleFix":"// before (rector.php)\n->withRules([AddReturnDocblockForDimFetchArrayFromAssignsRector::class])\n\n// after (rector.php) - removed; write by hand\n\n/**\n * @return array{id: int, name: string}\n */\npublic function buildRow(int $id): array","handlingStrategy":"validation","validationCode":"use Rector\\TypeDeclarationDocblocks\\Rector\\ClassMethod\\AddReturnDocblockForDimFetchArrayFromAssignsRector;\n\n$rules = [/* your list */ AddReturnDocblockForDimFetchArrayFromAssignsRector::class];\nif (in_array(AddReturnDocblockForDimFetchArrayFromAssignsRector::class, $rules, true)) {\n    throw new InvalidArgumentException('Rule deprecated; declare array shapes manually');\n}","typeGuard":null,"tryCatchPattern":"try {\n    exit($rectorApplication->run());\n} catch (\\Rector\\Exception\\ShouldNotHappenException $e) {\n    if (str_contains($e->getMessage(), 'AddReturnDocblockForDimFetchArrayFromAssignsRector')) {\n        fwrite(STDERR, 'Remove the rule; shapes guessed from assignments go stale as code evolves.' . PHP_EOL);\n        exit(1);\n    }\n    throw $e;\n}","preventionTips":["Prefer a small DTO/value object over a docblock array shape for evolving structures.","Where a shape is stable, write the @return docblock by hand next to the return type.","Keep docblock-generation rules out of shared configs; most were deprecated as unreliable."],"tags":["rector","php","docblock","array-shape","return-type","deprecated-rule"],"backgroundTag":"deprecated-api-invoked","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}