-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphparkitect.php
More file actions
84 lines (72 loc) · 3.41 KB
/
phparkitect.php
File metadata and controls
84 lines (72 loc) · 3.41 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
declare(strict_types=1);
use Arkitect\ClassSet;
use Arkitect\CLI\Config;
use Arkitect\Expression\ForClasses\DependsOnlyOnTheseNamespaces;
use Arkitect\Expression\ForClasses\HaveNameMatching;
use Arkitect\Expression\ForClasses\IsNotAbstract;
use Arkitect\Expression\ForClasses\MatchOneOfTheseNames;
use Arkitect\Expression\ForClasses\NotHaveDependencyOutsideNamespace;
use Arkitect\Expression\ForClasses\NotHaveNameMatching;
use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
use Arkitect\Rules\Rule;
return static function (Config $config): void {
$allowedVendors = ['Symfony\Component\Uid\Uuid', 'Assert', 'Doctrine\Common\Collections', 'DateTimeImmutable',
'DateTimeInterface', 'DateTime', 'Exception', 'Doctrine\ORM\EntityManagerInterface',
'Doctrine\ORM\EntityNotFoundException', 'Undabot\SymfonyJsonApi\Model\Collection\ObjectCollection'];
$srcClassSet = ClassSet::fromDir(__DIR__ . '/src');
$rules = [];
$rules[] = Rule::allClasses()
->except('App\Domain\*\Exception\*')
->that(new ResideInOneOfTheseNamespaces('App\Domain'))
->should(new NotHaveDependencyOutsideNamespace(
'App\Domain',
$allowedVendors,
))
->because('we want protect our domain');
$rules[] = Rule::allClasses()
->except('App\Application\Filter\*')
->that(new ResideInOneOfTheseNamespaces('App\Application'))
->should(new DependsOnlyOnTheseNamespaces(
'App\Domain',
'App\Application',
...$allowedVendors,
))
->because('we want protect our application');
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces(
'App\Infrastructure\Driving\Http\Mobile\v1\Endpoint',
))
->should(new HaveNameMatching('*Controller'))
->because('we want uniform naming for controllers');
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App'))
->should(new NotHaveNameMatching('*Manager'))
->because('*Manager is too vague in naming classes');
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App'))
->should(new NotHaveNameMatching('*Helper'))
->because('*Helper is too vague in naming classes');
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Infrastructure\Driving\Http\Mobile\v1\Endpoint'))
->should(new IsNotAbstract())
->because('we want to avoid abstract classes into our UI layer');
$rules[] = Rule::allClasses()
->that(new HaveNameMatching('*Handler'))
->should(new ResideInOneOfTheseNamespaces('App\Application', 'App\Infrastructure\Driven'))
->because('we want to be sure that all Handlers are in a specific namespace');
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces(
'App\Infrastructure\Driving\Http\Mobile\v1\Endpoint',
))
->should(new MatchOneOfTheseNames(['Create*', 'List*', 'Update*', 'Delete*', 'Get*']))
->because('we want uniform naming for controllers');
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces(
'App\Application\Repository',
))
->should(new MatchOneOfTheseNames(['*ReadRepository*', '*WriteRepository*']))
->because('we want uniform naming for Repositories');
$config
->add($srcClassSet, ...$rules);
};