-
Notifications
You must be signed in to change notification settings - Fork 0
/
phparkitect.php
74 lines (62 loc) · 3.16 KB
/
phparkitect.php
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
<?php
declare(strict_types=1);
/**
* Copyright (c) 2023-2024 Dezső Biczó
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/mxr576/ddqg-composer-audit/LICENSE.md
*
*/
use Arkitect\ClassSet;
use Arkitect\CLI\Config;
use Arkitect\Expression\ForClasses\IsFinal;
use Arkitect\Expression\ForClasses\NotDependsOnTheseNamespaces;
use Arkitect\Expression\ForClasses\NotHaveDependencyOutsideNamespace;
use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
use Arkitect\Rules\Rule;
return static function (Config $config): void {
$sourceFiles = ClassSet::fromDir(__DIR__ . '/src');
$rules = [];
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('mxr576\ddqgComposerAudit\Domain'))
->should(new NotHaveDependencyOutsideNamespace('mxr576\ddqgComposerAudit\Domain', [
'RuntimeException',
'DateTimeImmutable',
'Traversable',
'ArrayObject',
// We have to handle some Composer stuff as part of our domain, we do not
// want to redevelop them in the scope of a Composer plugin.
'Composer\Advisory\SecurityAdvisory',
'Composer\Semver\VersionParser',
'Composer\Semver\Constraint\ConstraintInterface',
'Composer\Semver\Constraint\Constraint',
]))
->because('We want to protect the Domain');
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('mxr576\ddqgComposerAudit\Domain'))
->should(new IsFinal())
->because('We want to protect our Domain');
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('mxr576\ddqgComposerAudit\Infrastructure'))
->should(new NotDependsOnTheseNamespaces('mxr576\ddqgComposerAudit\Application', 'mxr576\ddqgComposerAudit\Presentation', 'mxr576\ddqgComposerAudit\Supportive'))
->because('The Infrastructure layer should only depend on the Domain layer and on external namespaces. It is better if it does not depend on anything from Application. (See exceptions in baseline.)');
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('mxr576\ddqgComposerAudit\Presentation'))
->should(new NotDependsOnTheseNamespaces('mxr576\ddqgComposerAudit\Domain', 'mxr576\ddqgComposerAudit\Infrastructure'))
->because('The Presentation layer should only depend on the Application layer, stuff in Supportive and external namespaces.');
$rules[] = Rule::allClasses()
// Miscellaneous stuff that cannot go to any of these layers without breaking
// the "outer layers can only depend on elements from the same layer or
// inner layers" rule.
->that(new ResideInOneOfTheseNamespaces('mxr576\ddqgComposerAudit\Supportive'))
->should(new IsFinal())
->because('They are not part of the public API.');
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('mxr576\ddqgComposerAudit\Supportive'))
->should(new Arkitect\Expression\ForClasses\ContainDocBlockLike('@internal'))
->because('They are not part of the public API.');
$config
->add($sourceFiles, ...$rules);
};