Open
Description
Feature Request
Q | A |
---|---|
New Feature | yes |
RFC | yes |
BC Break | no |
Summary
We have some modules in the codebase that are designed to be standalone, depending only on PHP core classes. A typical example is our Clock module.
Currently, we express this constraint like this:
// The Clock module should be standalone.
// It can only use PHP core classes like DateTime.
Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('Acme\Clock'))
->should(new NotHaveDependencyOutsideNamespace(
'Acme\Clock',
externalDependenciesToExclude: ['DateTimeImmutable', 'DateTime']
))
->because('the Clock module must be almost standalone');
We’ve found this expression a bit verbose and hard to generalize. To make the intent more clear and easier to read, I’d like to propose supporting a more concise alternative:
Rule::namespace('Acme\Clock')
->canDependOnlyOn('DateTimeImmutable', 'DateTime');
This alternative would improve the readability of the rule, especially when applied to multiple modules with similar constraints (e.g., pure helpers, adapters, or low-level libraries).
Thanks!