{"record":{"id":"c5fd94027a85a3a0","repo":"rectorphp/rector","slug":"s-rule-is-deprecated-as-too-niche-use-a-custo","errorCode":null,"errorMessage":"\"%s\" rule is deprecated, as too niche; use a custom rule scoped to your own trait and interface pair instead","messagePattern":"\"(.+?)\" rule is deprecated, as too niche; use a custom rule scoped to your own trait and interface pair instead","errorType":"exception","errorClass":"ShouldNotHappenException","httpStatus":null,"severity":"error","filePath":"rules/Transform/Rector/Class_/AddInterfaceByTraitRector.php","lineNumber":47,"sourceCode":"{\n    use SomeTrait;\n}\nCODE_SAMPLE\n, ['SomeTrait' => 'SomeInterface'])]);\n    }\n    /**\n     * @return array<class-string<Node>>\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 too niche; use a custom rule scoped to your own trait and interface pair instead', self::class));\n    }\n    /**\n     * @param mixed[] $configuration\n     */\n    public function configure(array $configuration): void\n    {\n    }\n}\n","sourceCodeStart":29,"sourceCodeEnd":56,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/rules/Transform/Rector/Class_/AddInterfaceByTraitRector.php#L29-L56","documentation":"Rector\\Transform\\Rector\\Class_\\AddInterfaceByTraitRector is deprecated: refactor() throws Rector\\Exception\\ShouldNotHappenException on the first Class_ node. The rule added a configured interface to every class that used a configured trait, but that trait-to-interface pairing is too niche to ship generically. The configure() body is an empty no-op, so old trait/interface configuration is silently ignored before the exception fires.","triggerScenarios":"The rule is still referenced in rector.php (withRules() or withConfiguredRule() with the old trait=>interface map) and rector visits any class; refactor() throws immediately on the first Class_ node.","commonSituations":"Legacy configs from projects that bound e.g. a Laravel trait to a custom interface; rector upgrade breaking CI at the first class; configurations where the mapping was already ignored for a while without anyone noticing.","solutions":["Remove AddInterfaceByTraitRector from rector.php.","Add the interface to the relevant classes manually (usually a one-off, small set of classes).","If the pairing is a standing convention in your codebase, write a tiny custom rector rule scoped to that exact trait/interface pair."],"exampleFix":"// before (rector.php)\n->withConfiguredRule(AddInterfaceByTraitRector::class, [\n    SomeTrait::class => SomeInterface::class,\n])\n\n// after (rector.php) - removed\n\n// before\nclass Service\n{\n    use SomeTrait;\n}\n\n// after\nclass Service implements SomeInterface\n{\n    use SomeTrait;\n}","handlingStrategy":"validation","validationCode":"use Rector\\Transform\\Rector\\Class_\\AddInterfaceByTraitRector;\n\n$rules = [/* your list */ AddInterfaceByTraitRector::class];\nif (in_array(AddInterfaceByTraitRector::class, $rules, true)) {\n    throw new InvalidArgumentException('Rule deprecated; add the interface manually or via a custom scoped rule');\n}","typeGuard":null,"tryCatchPattern":"try {\n    exit($rectorApplication->run());\n} catch (\\Rector\\Exception\\ShouldNotHappenException $e) {\n    if (str_contains($e->getMessage(), 'AddInterfaceByTraitRector')) {\n        fwrite(STDERR, 'Remove the rule; the old trait=>interface configuration is ignored.' . PHP_EOL);\n        exit(1);\n    }\n    throw $e;\n}","preventionTips":["Encode project-specific trait/interface conventions in your own custom rule inside the project, not via generic Transform rules.","Notice the empty configure() body: configuration for this rule is silently discarded, so stale mappings hide in configs unnoticed.","Clean rector.php of Transform rules that no longer have working implementations after an upgrade."],"tags":["rector","php","interface","trait","transform","deprecated-rule"],"backgroundTag":"deprecated-api-invoked","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}