lint/style/prefer-class-constant
In the modernize and coding-style sets. Unsafe fix: it can change behaviour.
What it does
Use Foo::class instead of class-name strings.
Configuration
[lint.rules]
"style/prefer-class-constant" = "error"
To skip it in some files, add an override or a @pun-ignore-file comment.
Options
| Name | Type | Allowed values | Default | Upstream name |
|---|---|---|---|---|
namespaced-only |
bool |
Any | false |
None (Pun’s own) |
checks |
list |
class-name-resolution, string-class-name |
["class-name-resolution", "string-class-name"] |
None (Pun’s own) |
Replaces
class_keyword(php-cs-fixer, risky)StringClassNameToClassConstant(rector)UseClassKeywordForClassNameResolution(rector)no-literal-namespace-string(mago-linter)
Merged rules
These old IDs are now this rule. A config that still names one stops with an error. See merged rules.
lint/style/prefer-class-keywordlint/style/prefer-class-name-constant
Rector converts only names with a namespace, such as 'App\Models\User'; PHP-CS-Fixer’s class_keyword also converts global names such as 'Throwable'. namespaced-only = true keeps to Rector’s checks; pun migrate sets it when the rule comes from rector.php and not from class_keyword. checks keeps to the Rector rules rector.php runs: withPhpSets() runs only StringClassNameToClassConstantRector (checks = ["string-class-name"]), which leaves 'App\Foo::bar' alone.