{"record":{"id":"51ee7847c6d7b4d8","repo":"rectorphp/rector","slug":"s-rule-is-deprecated-as-the-deprecated-attr","errorCode":null,"errorMessage":"\"%s\" rule is deprecated, as the #[Deprecated] attribute triggers a runtime deprecation, unlike the @deprecated annotation; use \"phpstan/phpstan-deprecation-rules\" to report the annotation instead","messagePattern":"\"(.+?)\" rule is deprecated, as the #\\[Deprecated\\] attribute triggers a runtime deprecation, unlike the @deprecated annotation; use \"phpstan/phpstan-deprecation-rules\" to report the annotation instead","errorType":"exception","errorClass":"ShouldNotHappenException","httpStatus":null,"severity":"error","filePath":"rules/Php84/Rector/Class_/DeprecatedAnnotationToDeprecatedAttributeRector.php","lineNumber":49,"sourceCode":"CODE_SAMPLE\n, <<<'CODE_SAMPLE'\n#[\\Deprecated(message: 'Use SomeOtherFunction instead', since: '1.0.0')]\nfunction someFunction()\n{\n}\nCODE_SAMPLE\n)]);\n    }\n    public function getNodeTypes(): array\n    {\n        return [Function_::class, ClassMethod::class, ClassConst::class];\n    }\n    /**\n     * @param ClassConst|Function_|ClassMethod $node\n     */\n    public function refactor(Node $node): ?Node\n    {\n        throw new ShouldNotHappenException(sprintf('\"%s\" rule is deprecated, as the #[Deprecated] attribute triggers a runtime deprecation, unlike the @deprecated annotation; use \"phpstan/phpstan-deprecation-rules\" to report the annotation instead', self::class));\n    }\n    public function provideMinPhpVersion(): int\n    {\n        return PhpVersionFeature::DEPRECATED_ATTRIBUTE;\n    }\n}\n","sourceCodeStart":31,"sourceCodeEnd":56,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/rules/Php84/Rector/Class_/DeprecatedAnnotationToDeprecatedAttributeRector.php#L31-L56","documentation":"Rector\\Php84\\Rector\\Class_\\DeprecatedAnnotationToDeprecatedAttributeRector is deprecated: refactor() throws Rector\\Exception\\ShouldNotHappenException on the first Function_, ClassMethod or ClassConst node. The rule converted the passive @deprecated docblock annotation into the native #[Deprecated] attribute, but unlike the annotation the attribute triggers a real runtime deprecation notice whenever the element is called - a behavior change rector should not automate. The recommended replacement is the static-analysis package phpstan/phpstan-deprecation-rules, which reports @deprecated usage without runtime effects.","triggerScenarios":"The rule remains in rector.php (directly or copied from an old PHP 8.4 upgrade config) and rector visits any function, class method or class constant; refactor() throws on the first match.","commonSituations":"Running a PHP 8.4 level/set config built before the deprecation; CI failing right after a rector upgrade; teams wanting 'deprecated' warnings in CI without changing runtime behavior.","solutions":["Remove DeprecatedAnnotationToDeprecatedAttributeRector from rector.php.","Keep the @deprecated annotation and install phpstan/phpstan-deprecation-rules so PHPStan reports calls to deprecated code during static analysis.","Only add #[Deprecated] by hand on the rare element where a runtime notice is explicitly wanted."],"exampleFix":"// before (rector.php)\n->withRules([\n    DeprecatedAnnotationToDeprecatedAttributeRector::class,\n])\n\n// after (rector.php) - rule removed; keep the annotation and check it statically\n/**\n * @deprecated use Mailer::send() instead\n */\n// composer require --dev phpstan/phpstan-deprecation-rules","handlingStrategy":"validation","validationCode":"use Rector\\Php84\\Rector\\Class_\\DeprecatedAnnotationToDeprecatedAttributeRector;\n\n$rules = [/* your list */ DeprecatedAnnotationToDeprecatedAttributeRector::class];\nif (in_array(DeprecatedAnnotationToDeprecatedAttributeRector::class, $rules, true)) {\n    throw new InvalidArgumentException('Rule deprecated; use phpstan/phpstan-deprecation-rules instead');\n}","typeGuard":null,"tryCatchPattern":"try {\n    exit($rectorApplication->run());\n} catch (\\Rector\\Exception\\ShouldNotHappenException $e) {\n    if (str_contains($e->getMessage(), 'DeprecatedAnnotationToDeprecatedAttributeRector')) {\n        fwrite(STDERR, 'Remove the rule; keep @deprecated and report usage via phpstan/phpstan-deprecation-rules.' . PHP_EOL);\n        exit(1);\n    }\n    throw $e;\n}","preventionTips":["Before enabling PHP 8.4/8.5 rules wholesale, check the rule list against rector's current docs - deprecation-style rules were removed by design.","Use static analysis (phpstan-deprecation-rules) for deprecation reporting; reserve #[Deprecated] for deliberate runtime notices.","Grep rector.php for the rule class name after each rector upgrade."],"tags":["rector","php","deprecation","attributes","phpstan","php84"],"backgroundTag":"deprecated-api-invoked","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}