-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharkitect.php
More file actions
50 lines (40 loc) · 2.06 KB
/
arkitect.php
File metadata and controls
50 lines (40 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
declare(strict_types=1);
use Arkitect\ClassSet;
use Arkitect\CLI\Config;
use Arkitect\Expression\ForClasses\HaveNameMatching;
use Arkitect\Expression\ForClasses\NotDependsOnTheseNamespaces;
use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
use Arkitect\Rules\Rule;
return static function (Config $config): void {
$srcDir = getenv('BENCHMARK_SRC_DIR') ?: __DIR__ . '/symfony/src';
$classSet = ClassSet::fromDir($srcDir);
$rules = [];
// Rule 1: Classes in HttpFoundation do not depend on namespaces outside Symfony
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('Symfony\Component\HttpFoundation'))
->should(new NotDependsOnTheseNamespaces(
['Doctrine', 'Twig', 'Monolog', 'Psr\Log']
))
->because('HttpFoundation should remain framework-agnostic and not pull in heavy dependencies');
// Rule 2: Classes in Console\Command namespace must have names ending in "Command"
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('Symfony\Component\Console\Command'))
->should(new HaveNameMatching('*Command'))
->because('Console command classes must follow the Command suffix convention');
// Rule 3: Classes in EventDispatcher do not depend on namespaces outside Symfony
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('Symfony\Component\EventDispatcher'))
->should(new NotDependsOnTheseNamespaces(
['Doctrine', 'Twig']
))
->because('EventDispatcher should stay decoupled from persistence and templating layers');
// Rule 4: Classes in DependencyInjection do not depend on HTTP layer
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('Symfony\Component\DependencyInjection'))
->should(new NotDependsOnTheseNamespaces(
['Symfony\Component\HttpFoundation', 'Symfony\Component\HttpKernel']
))
->because('DependencyInjection should not depend on the HTTP layer');
$config->add($classSet, ...$rules);
};