Repository navigation
Add the No Bag Name Rule - #3
Open
GautierDele wants to merge 1 commit into
Open
GautierDele wants to merge 1 commit into
GautierDele wants to merge 1 commit into
Conversation
Refuse a class, interface, trait or enum whose name ends in a bag word (Service, Repository, Manager, Helper, Handler, Util or Utility, singular or plural), or that sits in a namespace with a Services, Repositories, Managers, Helpers, Handlers, Utils, Utilities, Support, Common or Misc segment. A well-named class in a Services namespace is still in a bag: the folder attracts classes the way the suffix attracts methods. A suffix is excused only when a third-party class or interface that the declaration directly extends or implements ends in the same word, a trailing Interface aside. A project parent never excuses it, and a bag namespace is never excused. A *ServiceProvider ends in Provider and is never reported. A code base that already has bags adopts the rule with a PHPStan baseline.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A tenth rule,
NoBagNameRule(identifierxefi.noBagName). It refuses a class, interface, trait or enum that:Service,Repository,Manager,Helper,Handler,UtilorUtility, singular or plural;Support,CommonorMisc.A well-named class in a
Servicesnamespace is still in a bag: the folder attracts classes the way the suffix attracts methods, so the namespace counts as much as the name.Not reported:
Interfaceaside — and comes fromvendor/or from PHP itself:RefusingDatabaseManager extends MySQLDatabaseManager,DatabaseSessionHandler implements SessionHandlerInterface. A project parent never excuses it (InvoiceManager extends LegacyManageris reported), and a bag namespace is never excused.*ServiceProvider, which ends inProvider.Why
It is the tool behind the
no-god-classesskill of xefi/claude-skills (xefi/claude-skills#229), which says the check belongs in this package: a loaded skill still lets a well-named class land inServices/, and a review reads the class, not its folder. A code base that already has bags adopts the rule with a baseline (vendor/bin/phpstan analyse --generate-baseline): existing offences stay listed, any new one fails, and an entry left behind once its bag is dissolved is reported as unmatched. The README documents this.Please review
extension.neon, it is on by default, so a project that upgrades gets one error per existing bag until it generates a baseline. Worth a minor release and a line in the release notes.App\Repositorynamespace is reported (the*Repositorysuffix itself is excused, sinceServiceEntityRepositoryis a third-party parent). Should aRepositorynamespace segment be exempt, or left to the baseline?Tests
NoBagNameRuleTestcovers 12 cases: both offences, traits, a project parent, a vendor interface, a PHP interface, a bag namespace under a third-party parent, a contract named after its answer, a service provider, a bag word inside a name, and an anonymous class. Disabling the vendor check makes the three exemption cases fail.Services/before that folder was dissolved, and nothing after.phpstan analysestill reports 13 errors, all inBooleanPropertyNamingRule,NoDeleteCascadeLaravelRuleandCascadeDeleteVisitor, the files Close detection gaps in logic rules #1 touches. None comes from the new rule.