Repository navigation
Expand file tree
/
Copy pathphparkitect.php
More file actions
70 lines (58 loc) · 3.07 KB
/
Copy pathphparkitect.php
File metadata and controls
70 lines (58 loc) · 3.07 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
<?php
declare(strict_types=1);
/*
* Generated by clean-arch:make-arch-rules.
*
* Run it with `vendor/bin/phparkitect check`. Regenerate it after changing the
* directories or the validation rules in config/clean-architecture.php, and
* edit it by hand once you need rules the package does not generate.
*/
use App\Domain\Shared\BaseModel;
use Arkitect\ClassSet;
use Arkitect\CLI\Config;
use Arkitect\Expression\ForClasses\IsNotA;
use Arkitect\Expression\ForClasses\NotDependsOnTheseNamespaces;
use Arkitect\Expression\ForClasses\NotHaveNameMatching;
use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
use Arkitect\Rules\Rule;
use Illuminate\Console\Command;
return static function (Config $config): void {
// The IsNotA rules below are reflection based. With autoloading broken they
// report nothing and phparkitect exits 0, which is indistinguishable from a
// pass. Fail here instead. Change the BaseModel import above if you renamed
// or removed that class.
if (! class_exists(Command::class) || ! class_exists(BaseModel::class)) {
throw new RuntimeException(
'clean-architecture: autoloading does not resolve the application classes, '
.'so the reflection based rules would pass silently. Run composer dump-autoload.'
);
}
$rules = [];
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\\Domain'))
->should(new NotDependsOnTheseNamespaces(['App\\Application']))
->because('the domain layer must not depend on the application layer');
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\\Domain'))
->should(new NotDependsOnTheseNamespaces(['App\\Infrastructure']))
->because('the domain layer must not depend on the infrastructure layer');
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\\Application'))
->should(new NotDependsOnTheseNamespaces(['App\\Infrastructure']))
->because('the application layer must not depend on the infrastructure layer');
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\\Domain'))
->should(new NotHaveNameMatching('*Observer'))
->because('observers react to framework events and belong to the infrastructure layer');
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\\Infrastructure'))
->andThat(new IsNotA('Illuminate\\Mail\\Mailable'))
->andThat(new IsNotA('Illuminate\\Notifications\\Notification'))
->should(new IsNotA('Illuminate\\Contracts\\Queue\\ShouldQueue'))
->because('queued jobs orchestrate use cases and belong to the application layer');
$rules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App'))
->should(new ResideInOneOfTheseNamespaces('App\\Domain', 'App\\Application', 'App\\Infrastructure', 'App\\Providers'))
->because('every class of the application belongs to one of the three layers');
$config->add(ClassSet::fromDir(__DIR__.'/app'), ...$rules);
};