-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCakeRule.php
More file actions
262 lines (237 loc) · 14 KB
/
Copy pathCakeRule.php
File metadata and controls
262 lines (237 loc) · 14 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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<?php
declare(strict_types=1);
namespace Crustum\StructArmed\Cake;
use function sprintf;
use function strtolower;
/**
* Rule keys of the CakePHP preset.
*
* The full key set is enumerated here (one case per public rule) and derived
* deterministically by the static builders, so the rule groups and hosts share
* a single source of truth. `Architecture::skip()`, `skipRule()` and
* `replaceRule()` are string-keyed upstream, so hosts pass `CakeRule::X->value`.
*
* Safety keys (`cakephp.safety.<layer>_no_<fn|construct>`) are deliberately not
* enumerated — they are derived per layer in the safety rule group.
*/
enum CakeRule: string
{
// Layer isolation
case TABLE_NOT_DEPEND_CONTROLLER = 'cakephp.layer.table_not_depend_controller';
case TABLE_NOT_DEPEND_VIEW = 'cakephp.layer.table_not_depend_view';
case ENTITY_NOT_DEPEND_CONTROLLER = 'cakephp.layer.entity_not_depend_controller';
case ENTITY_NOT_DEPEND_VIEW = 'cakephp.layer.entity_not_depend_view';
case VIEW_NOT_DEPEND_TABLE = 'cakephp.layer.view_not_depend_table';
case VIEW_NOT_DEPEND_CONTROLLER = 'cakephp.layer.view_not_depend_controller';
case HELPER_NOT_DEPEND_TABLE = 'cakephp.layer.helper_not_depend_table';
case HELPER_NOT_DEPEND_CONTROLLER = 'cakephp.layer.helper_not_depend_controller';
case CELL_NOT_DEPEND_CONTROLLER = 'cakephp.layer.cell_not_depend_controller';
case COMMAND_NOT_DEPEND_VIEW = 'cakephp.layer.command_not_depend_view';
case MAILER_NOT_DEPEND_CONTROLLER = 'cakephp.layer.mailer_not_depend_controller';
case MAILER_NOT_DEPEND_VIEW = 'cakephp.layer.mailer_not_depend_view';
case MIDDLEWARE_NOT_DEPEND_CONTROLLER = 'cakephp.layer.middleware_not_depend_controller';
case MIDDLEWARE_NOT_DEPEND_VIEW = 'cakephp.layer.middleware_not_depend_view';
case FORM_NOT_DEPEND_CONTROLLER = 'cakephp.layer.form_not_depend_controller';
case FORM_NOT_DEPEND_VIEW = 'cakephp.layer.form_not_depend_view';
case TYPE_NOT_DEPEND_TABLE = 'cakephp.layer.type_not_depend_table';
case TYPE_NOT_DEPEND_CONTROLLER = 'cakephp.layer.type_not_depend_controller';
case TYPE_NOT_DEPEND_VIEW = 'cakephp.layer.type_not_depend_view';
case ROUTE_NOT_DEPEND_CONTROLLER = 'cakephp.layer.route_not_depend_controller';
case ROUTE_NOT_DEPEND_VIEW = 'cakephp.layer.route_not_depend_view';
case WIDGET_NOT_DEPEND_TABLE = 'cakephp.layer.widget_not_depend_table';
case WIDGET_NOT_DEPEND_CONTROLLER = 'cakephp.layer.widget_not_depend_controller';
case CACHE_ENGINE_NOT_DEPEND_TABLE = 'cakephp.layer.cacheengine_not_depend_table';
case CACHE_ENGINE_NOT_DEPEND_CONTROLLER = 'cakephp.layer.cacheengine_not_depend_controller';
case CACHE_ENGINE_NOT_DEPEND_VIEW = 'cakephp.layer.cacheengine_not_depend_view';
case LOG_ENGINE_NOT_DEPEND_TABLE = 'cakephp.layer.logengine_not_depend_table';
case LOG_ENGINE_NOT_DEPEND_CONTROLLER = 'cakephp.layer.logengine_not_depend_controller';
case LOG_ENGINE_NOT_DEPEND_VIEW = 'cakephp.layer.logengine_not_depend_view';
case MAILER_TRANSPORT_NOT_DEPEND_TABLE = 'cakephp.layer.mailertransport_not_depend_table';
case MAILER_TRANSPORT_NOT_DEPEND_CONTROLLER = 'cakephp.layer.mailertransport_not_depend_controller';
case MAILER_TRANSPORT_NOT_DEPEND_VIEW = 'cakephp.layer.mailertransport_not_depend_view';
case EVENT_NOT_DEPEND_CONTROLLER = 'cakephp.layer.event_not_depend_controller';
case EVENT_NOT_DEPEND_VIEW = 'cakephp.layer.event_not_depend_view';
case POLICY_NOT_DEPEND_CONTROLLER = 'cakephp.layer.policy_not_depend_controller';
case POLICY_NOT_DEPEND_VIEW = 'cakephp.layer.policy_not_depend_view';
case AUTHENTICATOR_NOT_DEPEND_CONTROLLER = 'cakephp.layer.authenticator_not_depend_controller';
case AUTHENTICATOR_NOT_DEPEND_VIEW = 'cakephp.layer.authenticator_not_depend_view';
case IDENTIFIER_NOT_DEPEND_CONTROLLER = 'cakephp.layer.identifier_not_depend_controller';
case IDENTIFIER_NOT_DEPEND_VIEW = 'cakephp.layer.identifier_not_depend_view';
case PASSWORD_HASHER_NOT_DEPEND_TABLE = 'cakephp.layer.passwordhasher_not_depend_table';
case PASSWORD_HASHER_NOT_DEPEND_CONTROLLER = 'cakephp.layer.passwordhasher_not_depend_controller';
case PASSWORD_HASHER_NOT_DEPEND_VIEW = 'cakephp.layer.passwordhasher_not_depend_view';
case URL_CHECKER_NOT_DEPEND_TABLE = 'cakephp.layer.urlchecker_not_depend_table';
case URL_CHECKER_NOT_DEPEND_CONTROLLER = 'cakephp.layer.urlchecker_not_depend_controller';
case URL_CHECKER_NOT_DEPEND_VIEW = 'cakephp.layer.urlchecker_not_depend_view';
// Naming
case CONTROLLER_NAME_MUST_END_WITH_CONTROLLER = 'cakephp.controller.name_must_end_with_controller';
case TABLE_NAME_MUST_END_WITH_TABLE = 'cakephp.table.name_must_end_with_table';
case BEHAVIOR_NAME_MUST_END_WITH_BEHAVIOR = 'cakephp.behavior.name_must_end_with_behavior';
case COMPONENT_NAME_MUST_END_WITH_COMPONENT = 'cakephp.component.name_must_end_with_component';
case CELL_NAME_MUST_END_WITH_CELL = 'cakephp.cell.name_must_end_with_cell';
case HELPER_NAME_MUST_END_WITH_HELPER = 'cakephp.helper.name_must_end_with_helper';
case COMMAND_NAME_MUST_END_WITH_COMMAND = 'cakephp.command.name_must_end_with_command';
case MAILER_NAME_MUST_END_WITH_MAILER = 'cakephp.mailer.name_must_end_with_mailer';
case MIDDLEWARE_NAME_MUST_END_WITH_MIDDLEWARE = 'cakephp.middleware.name_must_end_with_middleware';
case FORM_NAME_MUST_END_WITH_FORM = 'cakephp.form.name_must_end_with_form';
case TYPE_NAME_MUST_END_WITH_TYPE = 'cakephp.type.name_must_end_with_type';
case ROUTE_NAME_MUST_END_WITH_ROUTE = 'cakephp.route.name_must_end_with_route';
case WIDGET_NAME_MUST_END_WITH_WIDGET = 'cakephp.widget.name_must_end_with_widget';
case CACHE_ENGINE_NAME_MUST_END_WITH_ENGINE = 'cakephp.cacheengine.name_must_end_with_engine';
case LOG_ENGINE_NAME_MUST_END_WITH_LOG = 'cakephp.logengine.name_must_end_with_log';
case MAILER_TRANSPORT_NAME_MUST_END_WITH_TRANSPORT = 'cakephp.mailertransport.name_must_end_with_transport';
case POLICY_NAME_MUST_END_WITH_POLICY = 'cakephp.policy.name_must_end_with_policy';
case AUTHENTICATOR_NAME_MUST_END_WITH_AUTHENTICATOR = 'cakephp.authenticator.name_must_end_with_authenticator';
case IDENTIFIER_NAME_MUST_END_WITH_IDENTIFIER = 'cakephp.identifier.name_must_end_with_identifier';
case PASSWORD_HASHER_NAME_MUST_END_WITH_PASSWORD_HASHER = 'cakephp.passwordhasher.name_must_end_with_passwordhasher';
case URL_CHECKER_NAME_MUST_END_WITH_URL_CHECKER = 'cakephp.urlchecker.name_must_end_with_urlchecker';
// Controller quality
case CONTROLLER_MAX_COMPLEXITY = 'cakephp.controller.max_complexity';
case CONTROLLER_MAX_METHOD_LENGTH = 'cakephp.controller.max_method_length';
case CONTROLLER_MAX_DEPENDENCIES = 'cakephp.controller.max_dependencies';
case CONTROLLER_NO_SUPERGLOBALS = 'cakephp.controller.no_superglobals';
case CONTROLLER_MUST_HAVE_RETURN_TYPES = 'cakephp.controller.must_have_return_types';
// Model / ORM quality
case TABLE_NO_SUPERGLOBALS = 'cakephp.table.no_superglobals';
case TABLE_MUST_HAVE_RETURN_TYPES = 'cakephp.table.must_have_return_types';
case ENTITY_NO_SUPERGLOBALS = 'cakephp.entity.no_superglobals';
case ENTITY_MUST_HAVE_RETURN_TYPES = 'cakephp.entity.must_have_return_types';
case BEHAVIOR_MUST_HAVE_RETURN_TYPES = 'cakephp.behavior.must_have_return_types';
// View / Cell / Helper quality
case VIEW_MAX_COMPLEXITY = 'cakephp.view.max_complexity';
case VIEW_NO_SUPERGLOBALS = 'cakephp.view.no_superglobals';
case CELL_MAX_COMPLEXITY = 'cakephp.cell.max_complexity';
case CELL_MUST_HAVE_RETURN_TYPES = 'cakephp.cell.must_have_return_types';
case HELPER_NO_SUPERGLOBALS = 'cakephp.helper.no_superglobals';
case HELPER_MUST_HAVE_RETURN_TYPES = 'cakephp.helper.must_have_return_types';
// Command quality
case COMMAND_MAX_COMPLEXITY = 'cakephp.command.max_complexity';
case COMMAND_NO_SUPERGLOBALS = 'cakephp.command.no_superglobals';
case COMMAND_MUST_HAVE_RETURN_TYPES = 'cakephp.command.must_have_return_types';
// Mailer quality
case MAILER_MAX_COMPLEXITY = 'cakephp.mailer.max_complexity';
case MAILER_NO_SUPERGLOBALS = 'cakephp.mailer.no_superglobals';
case MAILER_MUST_HAVE_RETURN_TYPES = 'cakephp.mailer.must_have_return_types';
// Middleware quality
case MIDDLEWARE_MAX_COMPLEXITY = 'cakephp.middleware.max_complexity';
case MIDDLEWARE_NO_SUPERGLOBALS = 'cakephp.middleware.no_superglobals';
case MIDDLEWARE_MUST_HAVE_RETURN_TYPES = 'cakephp.middleware.must_have_return_types';
// Form quality
case FORM_MAX_COMPLEXITY = 'cakephp.form.max_complexity';
case FORM_NO_SUPERGLOBALS = 'cakephp.form.no_superglobals';
case FORM_MUST_HAVE_RETURN_TYPES = 'cakephp.form.must_have_return_types';
// Type quality
case TYPE_MAX_COMPLEXITY = 'cakephp.type.max_complexity';
case TYPE_NO_SUPERGLOBALS = 'cakephp.type.no_superglobals';
case TYPE_MUST_HAVE_RETURN_TYPES = 'cakephp.type.must_have_return_types';
// Route / Widget quality
case ROUTE_MAX_COMPLEXITY = 'cakephp.route.max_complexity';
case ROUTE_NO_SUPERGLOBALS = 'cakephp.route.no_superglobals';
case ROUTE_MUST_HAVE_RETURN_TYPES = 'cakephp.route.must_have_return_types';
case WIDGET_MAX_COMPLEXITY = 'cakephp.widget.max_complexity';
case WIDGET_NO_SUPERGLOBALS = 'cakephp.widget.no_superglobals';
case WIDGET_MUST_HAVE_RETURN_TYPES = 'cakephp.widget.must_have_return_types';
// CacheEngine / LogEngine quality
case CACHE_ENGINE_MAX_COMPLEXITY = 'cakephp.cacheengine.max_complexity';
case CACHE_ENGINE_NO_SUPERGLOBALS = 'cakephp.cacheengine.no_superglobals';
case CACHE_ENGINE_MUST_HAVE_RETURN_TYPES = 'cakephp.cacheengine.must_have_return_types';
case LOG_ENGINE_MAX_COMPLEXITY = 'cakephp.logengine.max_complexity';
case LOG_ENGINE_NO_SUPERGLOBALS = 'cakephp.logengine.no_superglobals';
case LOG_ENGINE_MUST_HAVE_RETURN_TYPES = 'cakephp.logengine.must_have_return_types';
// MailerTransport quality
case MAILER_TRANSPORT_MAX_COMPLEXITY = 'cakephp.mailertransport.max_complexity';
case MAILER_TRANSPORT_NO_SUPERGLOBALS = 'cakephp.mailertransport.no_superglobals';
case MAILER_TRANSPORT_MUST_HAVE_RETURN_TYPES = 'cakephp.mailertransport.must_have_return_types';
// Event quality
case EVENT_MAX_COMPLEXITY = 'cakephp.event.max_complexity';
case EVENT_NO_SUPERGLOBALS = 'cakephp.event.no_superglobals';
case EVENT_MUST_HAVE_RETURN_TYPES = 'cakephp.event.must_have_return_types';
// Policy / Authenticator / Identifier quality
case POLICY_MAX_COMPLEXITY = 'cakephp.policy.max_complexity';
case POLICY_NO_SUPERGLOBALS = 'cakephp.policy.no_superglobals';
case POLICY_MUST_HAVE_RETURN_TYPES = 'cakephp.policy.must_have_return_types';
case AUTHENTICATOR_MAX_COMPLEXITY = 'cakephp.authenticator.max_complexity';
case AUTHENTICATOR_NO_SUPERGLOBALS = 'cakephp.authenticator.no_superglobals';
case AUTHENTICATOR_MUST_HAVE_RETURN_TYPES = 'cakephp.authenticator.must_have_return_types';
case IDENTIFIER_MAX_COMPLEXITY = 'cakephp.identifier.max_complexity';
case IDENTIFIER_NO_SUPERGLOBALS = 'cakephp.identifier.no_superglobals';
case IDENTIFIER_MUST_HAVE_RETURN_TYPES = 'cakephp.identifier.must_have_return_types';
// PasswordHasher / UrlChecker quality
case PASSWORD_HASHER_MAX_COMPLEXITY = 'cakephp.passwordhasher.max_complexity';
case PASSWORD_HASHER_NO_SUPERGLOBALS = 'cakephp.passwordhasher.no_superglobals';
case PASSWORD_HASHER_MUST_HAVE_RETURN_TYPES = 'cakephp.passwordhasher.must_have_return_types';
case URL_CHECKER_MAX_COMPLEXITY = 'cakephp.urlchecker.max_complexity';
case URL_CHECKER_NO_SUPERGLOBALS = 'cakephp.urlchecker.no_superglobals';
case URL_CHECKER_MUST_HAVE_RETURN_TYPES = 'cakephp.urlchecker.must_have_return_types';
/**
* Naming rule key for a layer: `cakephp.<layer>.name_must_end_with_<suffix>`.
*
* @throws \ValueError When the derived key is not enumerated
*/
public static function naming(CakeLayer $layer, string $suffix): self
{
return self::from(sprintf(
'cakephp.%s.name_must_end_with_%s',
strtolower($layer->value),
strtolower($suffix),
));
}
/**
* Isolation rule key: `cakephp.layer.<from>_not_depend_<to>`.
*
* @throws \ValueError When the derived key is not enumerated
*/
public static function notDepend(CakeLayer $from, CakeLayer $to): self
{
return self::from(sprintf(
'cakephp.layer.%s_not_depend_%s',
strtolower($from->value),
strtolower($to->value),
));
}
/**
* Complexity cap key: `cakephp.<layer>.max_complexity`.
*
* @throws \ValueError When the derived key is not enumerated
*/
public static function maxComplexity(CakeLayer $layer): self
{
return self::from(sprintf('cakephp.%s.max_complexity', strtolower($layer->value)));
}
/**
* Method-length cap key: `cakephp.<layer>.max_method_length`.
*
* @throws \ValueError When the derived key is not enumerated
*/
public static function maxMethodLength(CakeLayer $layer): self
{
return self::from(sprintf('cakephp.%s.max_method_length', strtolower($layer->value)));
}
/**
* Dependency-count cap key: `cakephp.<layer>.max_dependencies`.
*
* @throws \ValueError When the derived key is not enumerated
*/
public static function maxDependencies(CakeLayer $layer): self
{
return self::from(sprintf('cakephp.%s.max_dependencies', strtolower($layer->value)));
}
/**
* No-superglobals key: `cakephp.<layer>.no_superglobals`.
*
* @throws \ValueError When the derived key is not enumerated
*/
public static function noSuperglobals(CakeLayer $layer): self
{
return self::from(sprintf('cakephp.%s.no_superglobals', strtolower($layer->value)));
}
/**
* Return-types key: `cakephp.<layer>.must_have_return_types`.
*
* @throws \ValueError When the derived key is not enumerated
*/
public static function mustHaveReturnTypes(CakeLayer $layer): self
{
return self::from(sprintf('cakephp.%s.must_have_return_types', strtolower($layer->value)));
}
}