class-not-found
What it does
Section titled “What it does”Reports a class, interface or trait name written where a class is used (new, a type of a parameter, return value or property, catch, instanceof, the class of a static call or static property) that no file declares. The name is looked up in the project’s files and in the files Composer’s autoload rules (composer.json and the installed packages) name for it. A name outside every autoload prefix, or one that a conditional or run-time declaration may declare, is not reported.
Why it matters
Section titled “Why it matters”A class that cannot be found fails at run time with an Error the moment the line runs, and a type that cannot be found makes the check of the argument or the return value fail.
To fix, install the package that holds the class, correct the name or the use import, or declare the class.
Configuration
Section titled “Configuration”php: lint: rules: class-not-found: warn # off (default), warn, errorEnabled by the presets: php/phpstan.
Suppress one line with sudsy-disable-next-line class-not-found in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| phpstan | class.notFound |
partial | Only a name that a Composer autoload prefix of the project or its installed packages owns, whose file is missing; a class of an optional package that is not installed (no prefix owns it), the class of Foo::CONST, and the names of extends, implements and use are not looked at. |