{"record":{"id":"c11a6805e1bc6d6e","repo":"rectorphp/rector","slug":"s-rule-is-deprecated-as-property-hooks-are-a-m","errorCode":null,"errorMessage":"\"%s\" rule is deprecated, as property hooks are a matter of preference. They provide no upgrade value and make the code harder to read","messagePattern":"\"(.+?)\" rule is deprecated, as property hooks are a matter of preference\\. They provide no upgrade value and make the code harder to read","errorType":"exception","errorClass":"ShouldNotHappenException","httpStatus":null,"severity":"error","filePath":"rules/Php84/Rector/Class_/PropertyHookRector.php","lineNumber":60,"sourceCode":"    {\n        get => $this->name;\n        set($value) => $this->name = ucfirst($value);\n    }\n}\n\nCODE_SAMPLE\n)]);\n    }\n    public function getNodeTypes(): array\n    {\n        return [Class_::class];\n    }\n    /**\n     * @param Class_ $node\n     */\n    public function refactor(Node $node): ?Node\n    {\n        throw new ShouldNotHappenException(sprintf('\"%s\" rule is deprecated, as property hooks are a matter of preference. They provide no upgrade value and make the code harder to read', self::class));\n    }\n    public function provideMinPhpVersion(): int\n    {\n        return PhpVersionFeature::PROPERTY_HOOKS;\n    }\n}\n","sourceCodeStart":42,"sourceCodeEnd":67,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/rules/Php84/Rector/Class_/PropertyHookRector.php#L42-L67","documentation":"Rector\\Php84\\Rector\\Class_\\PropertyHookRector is deprecated: refactor() throws Rector\\Exception\\ShouldNotHappenException on the first Class_ node. The rule rewrote getter/setter method pairs into PHP 8.4 property hooks, but hooks are a stylistic preference with no upgrade value, and the mechanical rewrite often made classes harder to read. The rule requires PhpVersionFeature::PROPERTY_HOOKS, so it only loads on PHP 8.4+ targets.","triggerScenarios":"The rule is still listed in a withPhp84()-style custom rule list or withRules() and rector visits any class declaration; refactor() throws immediately on the first Class_ node.","commonSituations":"Adopting a PHP 8.4 upgrade config copied from an older template; CI breaking after a rector upgrade that gutted the rule; teams that enabled it 'to try hooks' and forgot it in the config.","solutions":["Remove PropertyHookRector from rector.php; property hooks are opt-in style, not an upgrade step.","If the team genuinely prefers hooks, convert specific getter/setter pairs by hand and review each diff in code review.","Do not try to keep the rule via an older rector pin - it is intentionally gone."],"exampleFix":"// before (rector.php)\n->withRules([PropertyHookRector::class])\n\n// after (rector.php) - removed; convert by hand where wanted\n\n// manual, opt-in per case (PHP 8.4):\npublic string $name {\n    set => trim($value);\n}","handlingStrategy":"validation","validationCode":"use Rector\\Php84\\Rector\\Class_\\PropertyHookRector;\n\n$rules = [/* your list */ PropertyHookRector::class];\nif (in_array(PropertyHookRector::class, $rules, true)) {\n    throw new InvalidArgumentException('PropertyHookRector is deprecated; property hooks are opt-in style, not an upgrade');\n}","typeGuard":null,"tryCatchPattern":"try {\n    exit($rectorApplication->run());\n} catch (\\Rector\\Exception\\ShouldNotHappenException $e) {\n    if (str_contains($e->getMessage(), 'PropertyHookRector')) {\n        fwrite(STDERR, 'Remove the rule; convert getter/setter pairs to hooks manually where the team wants them.' . PHP_EOL);\n        exit(1);\n    }\n    throw $e;\n}","preventionTips":["Decide property-hook adoption as a team style decision, then apply it by hand or in reviewed custom rules.","Keep a curated rule allowlist in rector.php instead of wildcard PHP-version rule bundles.","Remove deprecated rules immediately when rector reports them; leftover entries fail every later run."],"tags":["rector","php","property-hooks","php84","deprecated-rule"],"backgroundTag":"deprecated-api-invoked","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}