{"record":{"id":"91c4038b3c840717","repo":"rectorphp/rector","slug":"rule-s-was-not-found-smake-sure-it-is-register","errorCode":null,"errorMessage":"Rule \"%s\" was not found.%sMake sure it is registered in your config or in one of the sets","messagePattern":"Rule \"(.+?)\" was not found\\.(.+?)Make sure it is registered in your config or in one of the sets","errorType":"exception","errorClass":"RectorRuleNotFoundException","httpStatus":null,"severity":"error","filePath":"src/Configuration/OnlyRuleResolver.php","lineNumber":77,"sourceCode":"            $flattenMatching = [];\n            foreach ($this->rectors as $rector) {\n                if (str_replace('\\\\', '', get_class($rector)) === $rule) {\n                    $flattenMatching[] = get_class($rector);\n                }\n            }\n            $flattenMatching = array_unique($flattenMatching);\n            if (count($flattenMatching) === 1) {\n                return $flattenMatching[0];\n            }\n            $message = sprintf('Rule \"%s\" was not found.%sThe rule has no namespace. Make sure to escape the backslashes, and add quotes around the rule name: --only=\"My\\Rector\\Rule\"', $rule, \\PHP_EOL);\n        } else {\n            // the rule class exists, it is just missing in the config\n            if ($this->isRectorRuleClass($rule)) {\n                throw new RectorRuleNotFoundException($this->createUnregisteredMessage($rule));\n            }\n            $message = sprintf('Rule \"%s\" was not found.%sMake sure it is registered in your config or in one of the sets', $rule, \\PHP_EOL);\n        }\n        throw new RectorRuleNotFoundException($message);\n    }\n    /**\n     * Is this an existing rule class, that is just not registered in the config?\n     */\n    private function isRectorRuleClass(string $className): bool\n    {\n        if (!class_exists($className)) {\n            return \\false;\n        }\n        $reflectionClass = new ReflectionClass($className);\n        if ($reflectionClass->isAbstract()) {\n            return \\false;\n        }\n        return $reflectionClass->implementsInterface(RectorInterface::class);\n    }\n    private function createUnregisteredMessage(string $ruleClass): string\n    {\n        $shortRuleClass = (string) substr((string) strrchr($ruleClass, '\\\\'), 1);","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/src/Configuration/OnlyRuleResolver.php#L59-L95","documentation":"The terminal case of --only resolution: the namespaced value matched no registered rule AND is not an existing Rector rule class, so OnlyRuleResolver throws RectorRuleNotFoundException telling you to check registration and sets. Unlike the 'exists, but is not registered' variant, here the class itself is unknown to the autoloader -- typo, wrong namespace, or the rule lives in a package/version you do not have.","triggerScenarios":"Typos in the FQCN; a rule from a newer/older Rector version or from a split package (rector-symfony, rector-phpunit etc.) that is not installed; stale class names copied from outdated blog posts after renames.","commonSituations":"Upgrading Rector: rules renamed/moved namespaces; using a Symfony/PHPUnit-specific rule without the rector-symfony/rector-phpunit package installed; IDE autocomplete picking a similarly named class.","solutions":["Check the class exists in your vendor: grep -r 'class ReadOnlyPropertyRector' vendor/ or php -r \"var_dump(class_exists('...'));\"","Fix the namespace per your installed version (namespaces moved between major versions, e.g. Rector\\Rector... to Rector\\<Domain>\\Rector...)","If the rule ships in an optional package (rector-symfony, rector-phpunit, rector-doctrine...), composer require it first, then register it","Search the rule short name in your vendor's set files to see where it is registered: grep -rl 'SomeRector' vendor/rector --include='*.php'"],"exampleFix":"# before: rule lives in an optional package that is not installed\nvendor/bin/rector process src --only=\"Rector\\Symfony\\CodeQuality\\Rector\\ClassMethod\\RouteCollectionRector\"\n\n# after: install the package, then run\ncomposer require --dev rector/symfony\nvendor/bin/rector process src --only=\"Rector\\Symfony\\CodeQuality\\Rector\\ClassMethod\\RouteCollectionRector\"","handlingStrategy":"validation","validationCode":"// verify a rule class exists before passing it to --only\n$rule = 'Rector\\Symfony\\CodeQuality\\Rector\\ClassMethod\\RouteCollectionRector';\nif (! class_exists($rule) || ! is_subclass_of($rule, \\Rector\\Contract\\Rector\\RectorInterface::class, true)) {\n    fwrite(STDERR, \"Not an existing Rector rule: {$rule}\\n\");\n    exit(1);\n}","typeGuard":"function isExistingRectorRule(string $class): bool\n{\n    return class_exists($class)\n        && (new ReflectionClass($class))->implementsInterface(\\Rector\\Contract\\Rector\\RectorInterface::class)\n        && ! (new ReflectionClass($class))->isAbstract();\n}","tryCatchPattern":"catch \\Rector\\Exception\\Configuration\\RectorRuleNotFoundException; on the generic 'was not found' message, verify class_exists(), install any missing rector-* package, fix the namespace, and retry.","preventionTips":["Re-check rule FQCNs against your installed Rector version after every upgrade (namespaces shift between majors)","composer require the domain package (rector-symfony, rector-phpunit, ...) before using its rules","Prefer registering rules via sets rather than hand-typed FQCN strings"],"tags":["php","rector","cli","rule-selection","typo","package-missing"],"backgroundTag":"unknown-rule-class","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}