[BUG] Class dependencies leak between files
Bug Report
| Q | A |
|---|---|
| BC Break | - |
| Library Version | main branch |
| PHP version | 8.1.17 |
Summary
We are building our app as a modular monolith. We've defined a rule that each module can NOT depend on another module's namespace.
Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces($namespace))
->should(new NotDependsOnTheseNamespaces(...$otherModulesNamespaces)
->because('modules should NOT share code between each-other');
Each module can define its routes in a dedicated routes.php file in its directory where we use Laravel to define our routes with static calls to, for example, Route::post(). It means there is no class definition in the routes.php file.
Today after creating a second module, we received an error that our Controller in Module A depends on Module B when there's no import, static call, method call, or anything between the two. After a quick investigation, we've discovered a leak of the dependencies list in FileVisitor if one of the files has no class defined.
Current behavior
Arkitect reports violations:
App\DependenciesLeak\SecondModule\SomeClass has 1 violations
depends on App\DependenciesLeak\FirstModule\Router, but should not depend on these namespaces: App\DependenciesLeak\FirstModule because modules should be independent (on line 7)
How to reproduce
Please see #388 for the code snippets.
Expected behavior
No violations are reported and dependencies are not leaked between files