@@ -14,6 +14,15 @@ class NameValidationUtil
14
14
{
15
15
const PHP_CLASS_REGEX_PATTERN = '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/ ' ;
16
16
17
+ const DATA_ENTITY_NAME = "data entity name " ;
18
+ const DATA_ENTITY_KEY = "data entity key " ;
19
+ const METADATA_OPERATION_NAME = "metadata operation name " ;
20
+ const PAGE = "Page " ;
21
+ const SECTION = "Section " ;
22
+ const SECTION_ELEMENT_NAME = "section element name " ;
23
+ const ACTION_GROUP_NAME = "action group name " ;
24
+ const TEST_NAME = "test name " ;
25
+
17
26
/**
18
27
* The number of violations this instance has detected.
19
28
*
@@ -70,17 +79,18 @@ public static function validateName($name, $type)
70
79
}
71
80
72
81
/**
73
- * Validates data entity names .
82
+ * Validates that the string is PascalCase .
74
83
*
75
84
* @param string $str
85
+ * @param string $type
76
86
* @param string $filename
77
87
* @throws Exception
78
88
* @return void
79
89
*/
80
- public function validateDataEntityName ($ str , $ filename = null )
90
+ public function validatePascalCase ($ str, $ type , $ filename = null )
81
91
{
82
92
if (!ctype_upper ($ str [0 ])) {
83
- $ message = "The data entity name {$ str } should be PascalCase with an uppercase first letter. " ;
93
+ $ message = "The { $ type } {$ str } should be PascalCase with an uppercase first letter. " ;
84
94
85
95
if ($ filename !== null ) {
86
96
$ message .= " See file {$ filename }. " ;
@@ -97,44 +107,18 @@ public function validateDataEntityName($str, $filename = null)
97
107
}
98
108
99
109
/**
100
- * Validates data entity key names .
110
+ * Validates that the string is camelCase .
101
111
*
102
112
* @param string $str
113
+ * @param string $type
103
114
* @param string $filename
104
115
* @throws Exception
105
116
* @return void
106
117
*/
107
- public function validateDataEntityKey ($ str , $ filename = null )
118
+ public function validateCamelCase ($ str, $ type , $ filename = null )
108
119
{
109
120
if (!ctype_lower ($ str [0 ])) {
110
- $ message = "The data entity key {$ str } should be camelCase with a lowercase first letter. " ;
111
-
112
- if ($ filename !== null ) {
113
- $ message .= " See file {$ filename }. " ;
114
- }
115
-
116
- LoggingUtil::getInstance ()->getLogger (self ::class)->notification (
117
- $ message ,
118
- [],
119
- false
120
- );
121
-
122
- $ this ->count ++;
123
- }
124
- }
125
-
126
- /**
127
- * Validates metadata operation names.
128
- *
129
- * @param string $str
130
- * @param string $filename
131
- * @throws Exception
132
- * @return void
133
- */
134
- public function validateMetadataOperationName ($ str , $ filename = null )
135
- {
136
- if (!ctype_upper ($ str [0 ])) {
137
- $ message = "The metadata operation name {$ str } should be PascalCase with an uppercase first letter. " ;
121
+ $ message = "The {$ type } {$ str } should be camelCase with a lowercase first letter. " ;
138
122
139
123
if ($ filename !== null ) {
140
124
$ message .= " See file {$ filename }. " ;
@@ -151,133 +135,22 @@ public function validateMetadataOperationName($str, $filename = null)
151
135
}
152
136
153
137
/**
154
- * Validates page names.
155
- *
156
- * @param string $str
157
- * @param string $filename
158
- * @throws Exception
159
- * @return void
160
- */
161
- public function validatePageName ($ str , $ filename = null )
162
- {
163
- $ isPrefixAdmin = substr ($ str , 0 , 5 ) === "Admin " ;
164
- $ isPrefixStorefront = substr ($ str , 0 , 10 ) === "Storefront " ;
165
- $ isSuffixPage = substr ($ str , -4 ) === "Page " ;
166
-
167
- if ((!$ isPrefixAdmin && !$ isPrefixStorefront ) || !$ isSuffixPage ) {
168
- $ message = "The page name {$ str } should follow the pattern {Admin or Storefront}{Description}Page. " ;
169
-
170
- if ($ filename !== null ) {
171
- $ message .= " See file {$ filename }. " ;
172
- }
173
-
174
- LoggingUtil::getInstance ()->getLogger (self ::class)->notification (
175
- $ message ,
176
- [],
177
- false
178
- );
179
-
180
- $ this ->count ++;
181
- }
182
- }
183
-
184
- /**
185
- * Validates section names.
138
+ * Validates that the string is of the pattern {Admin or Storefront}{Description}{Type}.
186
139
*
187
140
* @param string $str
141
+ * @param string $type
188
142
* @param string $filename
189
143
* @throws Exception
190
144
* @return void
191
145
*/
192
- public function validateSectionName ($ str , $ filename = null )
146
+ public function validateAffixes ($ str, $ type , $ filename = null )
193
147
{
194
148
$ isPrefixAdmin = substr ($ str , 0 , 5 ) === "Admin " ;
195
149
$ isPrefixStorefront = substr ($ str , 0 , 10 ) === "Storefront " ;
196
- $ isSuffixSection = substr ($ str , -7 ) === "Section " ;
197
-
198
- if ((!$ isPrefixAdmin && !$ isPrefixStorefront ) || !$ isSuffixSection ) {
199
- $ message = "The section name {$ str } should follow the pattern {Admin or Storefront}{Description}Section. " ;
200
-
201
- if ($ filename !== null ) {
202
- $ message .= " See file {$ filename }. " ;
203
- }
204
-
205
- LoggingUtil::getInstance ()->getLogger (self ::class)->notification (
206
- $ message ,
207
- [],
208
- false
209
- );
210
-
211
- $ this ->count ++;
212
- }
213
- }
214
-
215
- /**
216
- * Validates section element names.
217
- *
218
- * @param string $str
219
- * @param string $filename
220
- * @throws Exception
221
- * @return void
222
- */
223
- public function validateElementName ($ str , $ filename = null )
224
- {
225
- if (!ctype_lower ($ str [0 ])) {
226
- $ message = "The element name {$ str } should be camelCase with a lowercase first letter. " ;
150
+ $ isSuffixType = substr ($ str , -strlen ($ type )) === $ type ;
227
151
228
- if ($ filename !== null ) {
229
- $ message .= " See file {$ filename }. " ;
230
- }
231
-
232
- LoggingUtil::getInstance ()->getLogger (self ::class)->notification (
233
- $ message ,
234
- [],
235
- false
236
- );
237
-
238
- $ this ->count ++;
239
- }
240
- }
241
-
242
- /**
243
- * Validates action group names.
244
- *
245
- * @param string $str
246
- * @param string $filename
247
- * @throws Exception
248
- * @return void
249
- */
250
- public function validateActionGroupName ($ str , $ filename = null )
251
- {
252
- if (!ctype_upper ($ str [0 ])) {
253
- $ message = "The action group name {$ str } should be PascalCase with an uppercase first letter. " ;
254
-
255
- if ($ filename !== null ) {
256
- $ message .= " See file {$ filename }. " ;
257
- }
258
-
259
- LoggingUtil::getInstance ()->getLogger (self ::class)->notification (
260
- $ message ,
261
- [],
262
- false
263
- );
264
-
265
- $ this ->count ++;
266
- }
267
- }
268
-
269
- /**
270
- * Validates test names.
271
- *
272
- * @param string $str
273
- * @param string $filename
274
- * @throws Exception
275
- * @return void
276
- */
277
- public function validateTestName ($ str , $ filename = null )
278
- {
279
- if (!ctype_upper ($ str [0 ])) {
280
- $ message = "The test name {$ str } should be PascalCase with an uppercase first letter. " ;
152
+ if ((!$ isPrefixAdmin && !$ isPrefixStorefront ) || !$ isSuffixType ) {
153
+ $ message = "The {$ type } name {$ str } should follow the pattern {Admin or Storefront}{Description} {$ type }. " ;
281
154
282
155
if ($ filename !== null ) {
283
156
$ message .= " See file {$ filename }. " ;
0 commit comments