{"record":{"id":"08732e3e4e58947f","repo":"rectorphp/rector","slug":"s-rule-is-deprecated-as-it-is-a-personal-prefe-08732e","errorCode":null,"errorMessage":"\"%s\" rule is deprecated, as it is a personal preference that makes array merges harder to read","messagePattern":"\"(.+?)\" rule is deprecated, as it is a personal preference that makes array merges harder to read","errorType":"exception","errorClass":"ShouldNotHappenException","httpStatus":null,"severity":"error","filePath":"rules/CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector.php","lineNumber":61,"sourceCode":"        $anotherValues = [...$iter1, ...$iter2];\n    }\n}\nCODE_SAMPLE\n)]);\n    }\n    /**\n     * @return array<class-string<Node>>\n     */\n    public function getNodeTypes(): array\n    {\n        return [FuncCall::class];\n    }\n    /**\n     * @param FuncCall $node\n     */\n    public function refactor(Node $node): ?Node\n    {\n        throw new ShouldNotHappenException(sprintf('\"%s\" rule is deprecated, as it is a personal preference that makes array merges harder to read', self::class));\n    }\n}\n","sourceCodeStart":43,"sourceCodeEnd":64,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/rules/CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector.php#L43-L64","documentation":"ArraySpreadInsteadOfArrayMergeRector used to rewrite array_merge($a, $b) into [...$a, ...$b]. It is deprecated because the change is a personal preference that can make merges harder to read, and array_merge still differs from spread (string keys are overwritten rather than renumbered). refactor() now throws ShouldNotHappenException on every FuncCall node; the rule exists purely to fail configurations that still enable it.","triggerScenarios":"Registering rules/CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector.php and running rector over any file containing a function call. The throw comes from rules/CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector.php:61 on the first FuncCall visited — effectively the first file.","commonSituations":"Configs that adopted the spread style for PHP 7.4+ performance still list this rule after upgrading rector/rector-prefixed. Since FuncCall matches every function call, the exception surfaces immediately and is often mistaken for a broken vendor directory.","solutions":["Remove ArraySpreadInsteadOfArrayMergeRector::class from rector.php and imported sets, then re-run dry-run","Convert array_merge to spread manually only for hot paths with integer-keyed arrays","Remember array_merge and spread are NOT equivalent for string keys — do not blindly swap","If the style must be enforced, encode it in a review checklist or a scoped custom rule"],"exampleFix":"// before (rector.php)\n->withRules([\n    \\Rector\\CodingStyle\\Rector\\FuncCall\\ArraySpreadInsteadOfArrayMergeRector::class,\n])\n// code:\n$all = array_merge($defaults, $overrides);\n\n// after (rector.php)\n// rule removed; manual conversion only where safe (integer keys):\n$all = [...$defaults, ...$overrides];\n// NOTE: with string keys, array_merge() and spread behave differently — keep array_merge()","handlingStrategy":"validation","validationCode":"$deprecated = ['ArraySpreadInsteadOfArrayMergeRector'];\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}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember spread and array_merge differ on string keys — never auto-swap","Convert to spread manually only in measured hot paths","Prune deprecated rules from rector.php before upgrading Rector","Dry-run a fixture in CI so tombstone rules break the build, not a developer's run"],"tags":["rector","php","deprecated-rule","array-merge","spread","code-style"],"backgroundTag":"rector-deprecated-rule","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}