-
-
Notifications
You must be signed in to change notification settings - Fork 48
Closed
Labels
enhancementNew feature or requestNew feature or request
Milestone
Description
Feature Request
Add the possibility to exclude namespaces from expressions
| Q | A |
|---|---|
| New Feature | yes |
| RFC | yes |
| BC Break | it depends |
Summary
After further discussion in this issue: #480, it became clear that there's currently no standard or intuitive way to exclude specific namespaces in expressions like NotDependsOnTheseNamespaces.
This expression uses a variadic parameter in its constructor, which makes it difficult to introduce additional arguments—such as an "exclude" array to define namespaces that should be ignored during the check.
We currently see two potential paths forward:
- Introduce a breaking change: Replace the variadic parameter with a standard array, allowing us to introduce a second parameter (e.g., for excluded namespaces). To maintain consistency, this change would need to be applied across all similar expressions, which could break existing implementations.
- Introduce a new rule, such as
ExcludeTheseNamespacesFromChecks, which would accept an array (or variadic arguments) of namespaces to be excluded. This would avoid breaking changes and keep existing rules intact.
Example:
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('')) // yes, some classes are not namespaced
->andThat(new NotResideInTheseNamespaces('App\Shop'))
->should(new NotDependsOnTheseNamespaces('App\Shop'))
->exclude(new ExcludeTheseNamespacesFromChecks('App\Shop\ShopFacade'))
->because('Other modules should only access Shop through ShopFacade');Or
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('')) // yes, some classes are not namespaced
->andThat(new NotResideInTheseNamespaces('App\Shop'))
->should(new NotDependsOnTheseNamespaces('App\Shop'))
->excludeTheseNamespacesFromChecks('App\Shop\ShopFacade')
->because('Other modules should only access Shop through ShopFacade');What do you think @fain182 @micheleorselli @pfazzi ?
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request