Class Naming Convention
debt(d3/e1/b1/t3)
Closest to 'default linter catches the common case' (d3). The detection_hints list phpcs, phpstan, and phpmd — all standard PHP tools that catch non-PascalCase class names automatically. phpcs with PSR-1 rules is widely used as a default linter in PHP projects, so violations are caught by default tooling rather than requiring a specialist setup.
Closest to 'one-line patch or single-call swap' (e1). The quick_fix is a simple rename: OrderProcessor not ProcessOrders. Renaming a class in a modern IDE is a single refactor action. Even if it touches multiple files (PSR-4 filename must match), the change per class is trivial and mechanical.
Closest to 'minimal commitment' (b1). This is a style/naming convention scoped to individual class declarations. It doesn't impose architectural weight, doesn't create cross-cutting dependencies, and doesn't slow down future maintainers beyond the one-time effort of learning the convention. It applies widely across contexts but carries no structural load.
Closest to 'minor surprise' (t3). The misconception field identifies one notable trap: redundant type suffixes (UserClass, OrderModel) feel like they add clarity but actually add noise. The common_mistakes also include all-caps acronyms (HTMLParser vs HtmlParser) which contradicts common instinct. These are edge-case surprises rather than fundamental behavioral inversions, warranting t3.
Also Known As
TL;DR
Explanation
PSR-1 mandates PascalCase for class names. Good class names are: specific (UserRepository not DataManager), nouns or noun phrases (Order, EmailService, InvoicePdfGenerator), and consistent with domain language. Avoid generic names (Manager, Handler, Helper, Processor) — they signal low cohesion. Abstract classes and interfaces have no required prefix/suffix in PSR standards but many teams use Interface suffix or I prefix for interfaces, Abstract prefix for abstract classes.
Common Misconception
Why It Matters
Common Mistakes
- snake_case or camelCase class names: user_service, userService — must be UserService.
- All-caps acronyms: HTMLParser — prefer HtmlParser (only first letter capped).
- Generic names: DataManager, BaseHelper — be specific about what the class does.
- Class name not matching filename — PSR-4 requires App\User to be in App/User.php.
Code Examples
// Wrong naming:
class user_repository { } // snake_case — wrong
class userService { } // camelCase — wrong
class PAYMENTGATEWAY { } // ALL_CAPS — wrong
class data_manager { } // Generic + snake_case
class HTMLrenderer { } // Inconsistent acronym caps
// Correct PascalCase, specific names:
class UserRepository { } // PascalCase, specific
class PaymentGateway { } // PascalCase, domain term
class HtmlRenderer { } // Acronym: only first letter capped
class InvoicePdfGenerator { } // Multi-word, clear purpose
class OrderNotFoundException extends RuntimeException { }