Skip to content

Commit d53cb62

Browse files
author
Florian Krämer
committed
Fixing layer rules
1 parent c497298 commit d53cb62

File tree

4 files changed

+18
-21
lines changed

4 files changed

+18
-21
lines changed

src/Architecture/ModularArchitectureRule.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,8 @@ private function validateCrossModuleDependency(
292292
string $usedClassName,
293293
int $line
294294
): ?RuleError {
295-
// Extract the class name from the full namespace
296-
$parts = explode('\\', $usedClassName);
297-
$className = end($parts);
298-
299-
// Check if it's an allowed cross-module import
300-
$isAllowed = $this->isAllowedCrossModuleImport($className);
295+
// Check if it's an allowed cross-module import using the full class name
296+
$isAllowed = $this->isAllowedCrossModuleImport($usedClassName);
301297

302298
if (!$isAllowed) {
303299
return RuleErrorBuilder::message(sprintf(
@@ -316,11 +312,12 @@ private function validateCrossModuleDependency(
316312

317313
/**
318314
* Check if a class is allowed for cross-module import
315+
* Matches against the fully qualified class name
319316
*/
320-
private function isAllowedCrossModuleImport(string $className): bool
317+
private function isAllowedCrossModuleImport(string $fullyQualifiedClassName): bool
321318
{
322319
foreach ($this->allowedCrossModulePatterns as $pattern) {
323-
if (preg_match($pattern, $className)) {
320+
if (preg_match($pattern, $fullyQualifiedClassName)) {
324321
return true;
325322
}
326323
}

tests/TestCases/Architecture/ModularArchitectureCustomCrossModuleRuleTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ protected function getRule(): Rule
2222
'App\\Capability',
2323
null, // Use default layer dependencies
2424
[
25-
'/Facade$/', // Keep default: Facade
26-
'/FacadeInterface$/', // Keep default: FacadeInterface
27-
'/Input$/', // Keep default: Input
28-
'/Result$/', // Keep default: Result
29-
'/Dto$/', // Custom: Allow Dto classes
25+
'/Facade$/', // Keep default: Facade
26+
'/FacadeInterface$/', // Keep default: FacadeInterface
27+
'/Input$/', // Keep default: Input
28+
'/Result$/', // Keep default: Result
29+
'/Dto$/', // Custom: Allow Dto classes
3030
]
3131
);
3232
}

tests/TestCases/Architecture/ModularArchitectureCustomLayersRuleTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ protected function getRule(): Rule
2727
'Presentation' => ['Application', 'Domain'],
2828
],
2929
[
30-
'/Facade$/',
31-
'/FacadeInterface$/',
32-
'/Input$/',
33-
'/Result$/',
30+
'/Facade$/', // Class names ending with Facade
31+
'/FacadeInterface$/', // Class names ending with FacadeInterface
32+
'/Input$/', // Class names ending with Input
33+
'/Result$/', // Class names ending with Result
3434
]
3535
);
3636
}

tests/TestCases/Architecture/ModularArchitectureRuleTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ protected function getRule(): Rule
1919
'App\\Capability',
2020
null,
2121
[
22-
'/Facade$/',
23-
'/FacadeInterface$/',
24-
'/Input$/',
25-
'/Result$/',
22+
'/Facade$/', // Class names ending with Facade
23+
'/FacadeInterface$/', // Class names ending with FacadeInterface
24+
'/Input$/', // Class names ending with Input
25+
'/Result$/', // Class names ending with Result
2626
]
2727
);
2828
}

0 commit comments

Comments
 (0)