-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphparkitect.php
182 lines (154 loc) · 8.67 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
declare(strict_types=1);
/*
* This file is part of the Valkyrja Framework package.
*
* (c) Melech Mizrachi <melechmizrachi@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Arkitect\ClassSet;
use Arkitect\CLI\Config;
use Arkitect\Expression\ForClasses\Extend;
use Arkitect\Expression\ForClasses\HaveAttribute;
use Arkitect\Expression\ForClasses\HaveNameMatching;
use Arkitect\Expression\ForClasses\IsEnum;
use Arkitect\Expression\ForClasses\IsFinal;
use Arkitect\Expression\ForClasses\IsInterface;
use Arkitect\Expression\ForClasses\IsNotAbstract;
use Arkitect\Expression\ForClasses\IsNotEnum;
use Arkitect\Expression\ForClasses\IsNotInterface;
use Arkitect\Expression\ForClasses\IsNotTrait;
use Arkitect\Expression\ForClasses\IsTrait;
use Arkitect\Expression\ForClasses\NotHaveNameMatching;
use Arkitect\Expression\ForClasses\NotResideInTheseNamespaces;
use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
use Arkitect\Rules\Rule;
use Valkyrja\Container\Support\Provider;
use Valkyrja\Orm\Entity\Entity;
use Valkyrja\Type\Model\Model;
use Valkyrja\Type\Type;
return static function (Config $config): void {
$srcClassSet = ClassSet::fromDir(__DIR__ . '/src');
$testClassSet = ClassSet::fromDir(__DIR__ . '/tests');
$srcRules = [];
$testRules = [];
// $srcRules[] = Rule::allClasses()
// ->that(new ResideInOneOfTheseNamespaces('*'))
// ->should(new ContainDocBlockLike('*@author Melech Mizrachi'))
// ->because('All classes should have an author');
$srcRules[] = Rule::allClasses()
->that(new HaveAttribute(Attribute::class))
->should(new ResideInOneOfTheseNamespaces('*Attribute\\'))
->because('All attributes should exist in an appropriate namespace');
// $srcRules[] = Rule::allClasses()
// ->that(new IsAbstract())
// ->andThat(new IsNotInterface())
// ->andThat(new IsNotFinal())
// ->andThat(new IsNotEnum())
// ->andThat(new IsNotTrait())
// ->andThat(new NotHaveNameMatching('*Factory'))
// ->andThat(new NotHaveNameMatching('*Provider'))
// ->andThat(new NotHaveNameMatching('*Security'))
// ->andThat(new NotResideInTheseNamespaces('*Provider'))
// ->should(new HaveNameMatching('*Abstract'))
// ->because('All abstract classes should be properly named');
$srcRules[] = Rule::allClasses()
->that(new IsFinal())
->andThat(new IsNotEnum())
->andThat(new IsNotInterface())
->andThat(new IsNotAbstract())
->andThat(new IsNotTrait())
->andThat(new NotHaveNameMatching('*Security'))
->andThat(new NotHaveNameMatching('*Provider'))
->should(new ResideInOneOfTheseNamespaces('*Constant\\'))
->because('All final classes are constants and should exist in an appropriate namespace');
$srcRules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('*Constant\\'))
->should(new IsFinal())
->because('All constants should be final');
$srcRules[] = Rule::allClasses()
->that(new Extend(Provider::class))
->should(new HaveNameMatching('*ServiceProvider'))
->because('All service providers should be named appropriately');
$srcRules[] = Rule::allClasses()
->that(new Extend(Provider::class))
->should(new ResideInOneOfTheseNamespaces('*Provider\\'))
->because('All service providers should exist in an appropriate namespace');
$srcRules[] = Rule::allClasses()
->that(new HaveNameMatching('*Factory'))
->should(new ResideInOneOfTheseNamespaces('*Factory\\'))
->because('All factories should exist in an appropriate namespace');
$srcRules[] = Rule::allClasses()
->that(new HaveNameMatching('*Security'))
->should(new ResideInOneOfTheseNamespaces('*Security\\'))
->because('All security classes should exist in an appropriate namespace');
$srcRules[] = Rule::allClasses()
->that(new HaveNameMatching('*Security'))
->should(new IsFinal())
->because('All security classes should be final');
$srcRules[] = Rule::allClasses()
->that(new Extend(Valkyrja\Config\Config::class))
->andThat(new NotHaveNameMatching('*Config'))
->should(new ResideInOneOfTheseNamespaces('*Config\\'))
->because('All config classes should exist in an appropriate namespace');
$srcRules[] = Rule::allClasses()
->that(new Extend(Throwable::class))
->should(new ResideInOneOfTheseNamespaces('*Exception\\'))
->because('All throwable objects or interfaces should exist in an appropriate namespace');
$srcRules[] = Rule::allClasses()
->that(new Extend(Type::class))
->andThat(new NotResideInTheseNamespaces('*Config'))
->andThat(new NotResideInTheseNamespaces('*Entity'))
->andThat(new NotResideInTheseNamespaces('*Model'))
->should(new ResideInOneOfTheseNamespaces('*Type\\'))
->because('All types should exist in an appropriate namespace');
$srcRules[] = Rule::allClasses()
->that(new Extend(Model::class))
->andThat(new NotResideInTheseNamespaces('*Config'))
->andThat(new NotResideInTheseNamespaces('*Entity'))
->should(new ResideInOneOfTheseNamespaces('*Model\\'))
->because('All models should exist in an appropriate namespace');
$srcRules[] = Rule::allClasses()
->that(new Extend(Entity::class))
->should(new ResideInOneOfTheseNamespaces('*Entity\\'))
->because('All entities should exist in an appropriate namespace');
$srcRules[] = Rule::allClasses()
->that(new IsInterface())
->andThat(new NotResideInTheseNamespaces('*Exception\\'))
->should(new ResideInOneOfTheseNamespaces('*Contract\\'))
->because('All interfaces are contracts and should be in an appropriate namespace');
$srcRules[] = Rule::allClasses()
->that(new IsEnum())
->should(new ResideInOneOfTheseNamespaces('*Enum\\'))
->because('All enums should be in an appropriate namespace');
$testRules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('*Classes\\'))
->andThat(new NotHaveNameMatching('*Enum'))
->andThat(new IsNotTrait())
->should(new HaveNameMatching('*Class'))
->because('Testable classes should be named appropriately');
$testRules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('*Classes\\'))
->should(new NotHaveNameMatching('*Test'))
->because('Testable classes are not tests');
$testRules[] = Rule::allClasses()
->that(new NotHaveNameMatching('*Test'))
->should(new NotResideInTheseNamespaces('*Unit\\', '*Functional\\'))
->because('Only tests should be in namespace');
$testRules[] = Rule::allClasses()
->that(new IsTrait())
->andThat(new NotHaveNameMatching('TestCase'))
->should(new ResideInOneOfTheseNamespaces('*Trait\\'))
->because('All test traits should be in an appropriate namespace');
$testRules[] = Rule::allClasses()
->that(new IsTrait())
->andThat(new NotHaveNameMatching('TestCase'))
->should(new HaveNameMatching('*Trait'))
->because('All test traits should be named appropriately');
$config
->add($srcClassSet, ...$srcRules);
$config
->add($testClassSet, ...$testRules);
};