Using Rector for checking namespace isolation #7110
Replies: 2 comments 5 replies
-
Hi, thanks for the question. Rector is rather A → B refacotring tool. What you look for is reporting tool - PHPStan. It does not specifically check the namespaces, but you can easily extend to handle that. |
Beta Was this translation helpful? Give feedback.
-
@dorrogeray With deptrac you can configure advanced rules for that and even generate an image of your dependencies and errors in the dependencies of one layer on the other layer. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I would like to create a tool which will enforce a rule where only classes from specified namespaces are allowed in some namespaces. Something along the lines of:
App\Services\<SomeNameSpace>\**
App\Services\<SomeNameSpace>\**
App\Models\<SomeNameSpace>\**
App\Exceptions\**
This would mean that any class inside
App\Services\<SomeNameSpace>\**
namespace could only use classes from following namespaces (+vendor):App\Services\<SomeNameSpace>\**
App\Models\<SomeNameSpace>\**
App\Exceptions\**
If a violation is found, it would be reported.
I like the power of Rector very much, but I am not sure if it makes sense to try to implement this as a rector rule. These violations will not be something that can be fixed automatically, only thing I can think of is Rector adding comments like
// WARNING: Usage of class XXX in namespace YYY is not allowed
, but it seems a bit obnoxious.What do you think, should I try to create a dedicated tool or is there a way to fit this rule into rector in some reasonable fashion?
Thanks for your feedback!
Beta Was this translation helpful? Give feedback.
All reactions