Pattern: Missing use of fully qualified exception
Issue: -
Reduces confusion in the following code snippet:
try {
$this->foo();
} catch (Exception $e) {
// Is this the general exception all exceptions must extend from? Or Exception from the current namespace?
}
All references to types named Exception
or ending with Exception
must be referenced via a fully qualified name:
try {
$this->foo();
} catch (\FooCurrentNamespace\Exception $e) {
} catch (\Exception $e) {
}
Rule provides the following settings:
- Exceptions with different names can be configured in
specialExceptionNames
property. - If your codebase uses classes that look like exceptions (because they have
Exception
orError
suffixes) but aren't, you can add them toignoredNames
property and the rule won't enforce them to be fully qualified. Classes withError
suffix have to be added to ignored only if they are in the root namespace (likeLibXMLError
).