{"record":{"id":"000061921674e4ab","repo":"rectorphp/rector","slug":"s-is-not-a-valid-s-name","errorCode":null,"errorMessage":"\"%s\" is not a valid %s name","messagePattern":"\"(.+?)\" is not a valid (.+?) name","errorType":"validation","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Validation/RectorAssert.php","lineNumber":73,"sourceCode":"    }\n    public static function methodName(string $name): void\n    {\n        self::elementName($name, self::METHOD_OR_CONSTANT_NAME_REGEX, 'method');\n    }\n    public static function functionName(string $name): void\n    {\n        self::elementName($name, self::FUNCTION_NAME_REGEX, 'function');\n    }\n    /**\n     * @api\n     */\n    public static function elementName(string $name, string $regex, string $elementType): void\n    {\n        if (StringUtils::isMatch($name, $regex)) {\n            return;\n        }\n        $errorMessage = sprintf('\"%s\" is not a valid %s name', $name, $elementType);\n        throw new InvalidArgumentException($errorMessage);\n    }\n}\n","sourceCodeStart":55,"sourceCodeEnd":76,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/src/Validation/RectorAssert.php#L55-L76","documentation":"RectorAssert::elementName() is the shared validator behind className/propertyName/methodName/constantName/functionName. It matches the name against a PHP identifier regex (class names may contain namespaces; function names may be namespaced; properties/methods/constants must be bare identifiers) and throws webmozart InvalidArgumentException('\"%s\" is not a valid %s name') on the first mismatch.","triggerScenarios":"Calling RectorAssert::functionName('my-function') (hyphen), className('App.Class') (dot), or methodName('9to5') (leading digit); passing names assembled from user input that never got sanitized.","commonSituations":"Custom rules validating configured identifiers (e.g. a rule driven by a function-name list from rector.php); config parsing where an FQCN arrives with wrong separators; generated names from templates containing dashes.","solutions":["Use valid PHP identifier characters: start [a-zA-Z_\\x80-\\xff], continue [a-zA-Z0-9_\\x80-\\xff], backslash-separated for namespaced class/function names","Sanitize/validate external input before passing it to the assert (preg_match the same pattern)","Fix separators: convert 'App.Class' to 'App\\\\Class'"],"exampleFix":"// before\nRectorAssert::functionName('my-function');\n\n// after\nRectorAssert::functionName('my_function');","handlingStrategy":"validation","validationCode":"// same shape Rector uses for bare identifiers\nfunction isValidPhpIdentifier(string $name): bool\n{\n    return preg_match('#^[a-zA-Z_\\x80-\\xff][a-zA-Z0-9_\\x80-\\xff]*$#', $name) === 1;\n}\n\n// namespaced class/function FQCNs\nfunction isValidPhpFqcn(string $name): bool\n{\n    return preg_match('#^[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*(\\\\\\\\[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)*$#', $name) === 1;\n}","typeGuard":null,"tryCatchPattern":"try {\n    RectorAssert::functionName($name);\n} catch (\\RectorPrefix202608\\Webmozart\\Assert\\InvalidArgumentException $e) {\n    // reject config input with a field-scoped message\n    $errors[] = \"config.functions: {$e->getMessage()}\";\n}","preventionTips":["Validate names at the config boundary (CLI/env/user input), not deep in rule execution","Build FQCNs with implode('\\\\', $segments) rather than string concat of dotted input","Keep a shared identifier-regex helper so wrappers and RectorAssert never drift"],"tags":["php","naming","validation","identifier","rector"],"backgroundTag":"identifier-validation-failed","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}