This rule suggests that class names in PHP should be descriptive and meaningful, rather than short and non-descriptive. This is important because meaningful class names make your code more readable and maintainable. They provide a clear idea of what the class is for, or what functionality it provides, without having to delve into the details of the class implementation.
Short class names like A, B, or C, on the other hand, are not immediately clear in their purpose, making it difficult for others and yourself to understand what the class is supposed to do at a glance. This can lead to confusion and can make the code harder to work with.
To avoid violating this rule, always give your classes, interfaces, and enums descriptive names. These names should be concise, yet clearly describe what the class, interface, or enum does. For instance, instead of naming a class that handles user authentication as A, name it UserAuthenticationHandler. This makes it immediately clear what the class is responsible for, enhancing the readability and maintainability of your code.
Non-Compliant Code Examples
<?phpclassA{}enumB{}interfaceC{}
Compliant Code Examples
<?phpclassFoo{}enumBar{}interfaceBaz{}
Seamless integrations. Try Datadog Code Analysis
Datadog Code Analysis
Try this rule and analyze your code with Datadog Code Analysis
How to use this rule
1
2
rulesets:- php-code-style # Rules to enforce PHP code style.
Create a static-analysis.datadog.yml with the content above at the root of your repository
Use our free IDE Plugins or add Code Analysis scans to your CI pipelines