Skip to content

Commit a4572cb

Browse files
authored
Merge pull request #24 from magento-commerce/imported-magento-magento-coding-standard-224
[Imported] AC-958: create unit test for Magento2\Annotation checks
2 parents a636ed7 + 38f32af commit a4572cb

6 files changed

+439
-25
lines changed

Magento2/Sniffs/Annotation/AnnotationFormatValidator.php

+13-13
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private function validateMultiLinesInShortDescription(
6464
&& $tokens[$shortPtrEnd]['code'] !== T_DOC_COMMENT_TAG
6565
) {
6666
$error = 'Short description should not be in multi lines';
67-
$phpcsFile->addFixableError($error, $shortPtrEnd + 1, 'MethodAnnotation');
67+
$phpcsFile->addError($error, $shortPtrEnd + 1, 'MethodAnnotation');
6868
}
6969
}
7070

@@ -95,7 +95,7 @@ private function validateSpacingBetweenShortAndLongDescriptions(
9595
&& $tokens[$shortPtrEnd]['code'] !== T_DOC_COMMENT_TAG
9696
) {
9797
$error = 'There must be exactly one blank line between lines short and long descriptions';
98-
$phpcsFile->addFixableError($error, $shortPtrEnd + 1, 'MethodAnnotation');
98+
$phpcsFile->addError($error, $shortPtrEnd + 1, 'MethodAnnotation');
9999
}
100100
if ($shortPtrEnd != $shortPtr) {
101101
$this->validateLongDescriptionFormat($phpcsFile, $shortPtrEnd, $commentEndPtr, $emptyTypeTokens);
@@ -123,16 +123,16 @@ private function validateShortDescriptionFormat(
123123
$tokens = $phpcsFile->getTokens();
124124
if ($tokens[$shortPtr]['line'] !== $tokens[$stackPtr]['line'] + 1) {
125125
$error = 'No blank lines are allowed before short description';
126-
$phpcsFile->addFixableError($error, $shortPtr, 'MethodAnnotation');
126+
$phpcsFile->addError($error, $shortPtr, 'MethodAnnotation');
127127
}
128128
if (strtolower($tokens[$shortPtr]['content']) === '{@inheritdoc}') {
129129
$error = 'If the @inheritdoc not inline it shouldn’t have braces';
130-
$phpcsFile->addFixableError($error, $shortPtr, 'MethodAnnotation');
130+
$phpcsFile->addError($error, $shortPtr, 'MethodAnnotation');
131131
}
132132
$shortPtrContent = $tokens[$shortPtr]['content'];
133133
if (preg_match('/^\p{Ll}/u', $shortPtrContent) === 1) {
134134
$error = 'Short description must start with a capital letter';
135-
$phpcsFile->addFixableError($error, $shortPtr, 'MethodAnnotation');
135+
$phpcsFile->addError($error, $shortPtr, 'MethodAnnotation');
136136
}
137137
$this->validateNoExtraNewLineBeforeShortDescription(
138138
$phpcsFile,
@@ -171,16 +171,16 @@ private function validateLongDescriptionFormat(
171171
$longPtr = $phpcsFile->findNext($emptyTypeTokens, $shortPtrEnd + 1, $commentEndPtr - 1, true);
172172
if (strtolower($tokens[$longPtr]['content']) === '@inheritdoc') {
173173
$error = '@inheritdoc imports only short description, annotation must have long description';
174-
$phpcsFile->addFixableError($error, $longPtr, 'MethodAnnotation');
174+
$phpcsFile->addError($error, $longPtr, 'MethodAnnotation');
175175
}
176176
if ($longPtr !== false && $tokens[$longPtr]['code'] === T_DOC_COMMENT_STRING) {
177177
if ($tokens[$longPtr]['line'] !== $tokens[$shortPtrEnd]['line'] + 2) {
178178
$error = 'There must be exactly one blank line between descriptions';
179-
$phpcsFile->addFixableError($error, $longPtr, 'MethodAnnotation');
179+
$phpcsFile->addError($error, $longPtr, 'MethodAnnotation');
180180
}
181181
if (preg_match('/^\p{Ll}/u', $tokens[$longPtr]['content']) === 1) {
182182
$error = 'Long description must start with a capital letter';
183-
$phpcsFile->addFixableError($error, $longPtr, 'MethodAnnotation');
183+
$phpcsFile->addError($error, $longPtr, 'MethodAnnotation');
184184
}
185185
}
186186
}
@@ -203,7 +203,7 @@ public function validateTagsSpacingFormat(File $phpcsFile, int $commentStartPtr,
203203
&& strtolower($commentTagPtrContent) !== '@inheritdoc'
204204
) {
205205
$error = 'There must be exactly one blank line before tags';
206-
$phpcsFile->addFixableError($error, $firstTagPtr, 'MethodAnnotation');
206+
$phpcsFile->addError($error, $firstTagPtr, 'MethodAnnotation');
207207
}
208208
}
209209
}
@@ -240,7 +240,7 @@ public function validateTagGroupingFormat(File $phpcsFile, int $commentStartPtr)
240240
if ($paramGroupId !== null
241241
&& $paramGroupId !== $groupId) {
242242
$error = 'Parameter tags must be grouped together';
243-
$phpcsFile->addFixableError($error, $tag, 'MethodAnnotation');
243+
$phpcsFile->addError($error, $tag, 'MethodAnnotation');
244244
}
245245
if ($paramGroupId === null) {
246246
$paramGroupId = $groupId;
@@ -273,7 +273,7 @@ public function validateTagAligningFormat(File $phpcsFile, int $commentStartPtr)
273273

274274
if (!$this->allTagsAligned($actualPositions)
275275
&& !$this->noneTagsAligned($actualPositions, $noAlignmentPositions)) {
276-
$phpcsFile->addFixableError(
276+
$phpcsFile->addError(
277277
'Tags visual alignment must be consistent',
278278
$stackPtr,
279279
'MethodArguments'
@@ -322,7 +322,7 @@ private function validateNoExtraNewLineBeforeShortDescription(
322322
$prevPtr = $phpcsFile->findPrevious($emptyTypeTokens, $commentEndPtr - 1, $commentStartPtr, true);
323323
if ($tokens[$prevPtr]['line'] < ($tokens[$commentEndPtr]['line'] - 1)) {
324324
$error = 'Additional blank lines found at end of the annotation block';
325-
$phpcsFile->addFixableError($error, $commentEndPtr, 'MethodAnnotation');
325+
$phpcsFile->addError($error, $commentEndPtr, 'MethodAnnotation');
326326
}
327327
}
328328

@@ -351,7 +351,7 @@ public function validateDescriptionFormatStructure(
351351
&& strtolower($commentTagPtrContent) !== '@inheritdoc'
352352
) {
353353
$error = 'Missing short description';
354-
$phpcsFile->addFixableError($error, $commentStartPtr, 'MethodAnnotation');
354+
$phpcsFile->addError($error, $commentStartPtr, 'MethodAnnotation');
355355
} else {
356356
$this->validateShortDescriptionFormat(
357357
$phpcsFile,

Magento2/Sniffs/Annotation/MethodArgumentsSniff.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,15 @@ private function validateParameterAnnotationForArgumentExists(
225225
$previousCommentClosePtr
226226
);
227227
if ($inheritdocAnnotationWithBracesExists) {
228-
$phpcsFile->addFixableError(
228+
$phpcsFile->addError(
229229
'{@inheritdoc} does not import parameter annotation',
230230
$stackPtr,
231231
'MethodArguments'
232232
);
233233
} elseif ($this->validateCommentBlockExists($phpcsFile, $previousCommentClosePtr, $stackPtr)
234234
&& !$inheritdocAnnotationWithoutBracesExists
235235
) {
236-
$phpcsFile->addFixableError(
236+
$phpcsFile->addError(
237237
'Missing @param for argument in method annotation',
238238
$stackPtr,
239239
'MethodArguments'
@@ -257,13 +257,13 @@ private function validateCommentBlockDoesnotHaveExtraParameterAnnotation(
257257
int $stackPtr
258258
): void {
259259
if ($argumentsCount < $parametersCount && $argumentsCount > 0) {
260-
$phpcsFile->addFixableError(
260+
$phpcsFile->addError(
261261
'Extra @param found in method annotation',
262262
$stackPtr,
263263
'MethodArguments'
264264
);
265265
} elseif ($argumentsCount > 0 && $argumentsCount != $parametersCount && $parametersCount != 0) {
266-
$phpcsFile->addFixableError(
266+
$phpcsFile->addError(
267267
'@param is not found for one or more params in method annotation',
268268
$stackPtr,
269269
'MethodArguments'
@@ -290,7 +290,7 @@ private function validateArgumentNameInParameterAnnotationExists(
290290
$parameterNames = $this->getMethodParameters($paramDefinitions);
291291
if (!in_array($methodArguments[$ptr], $parameterNames)) {
292292
$error = $methodArguments[$ptr] . ' parameter is missing in method annotation';
293-
$phpcsFile->addFixableError($error, $stackPtr, 'MethodArguments');
293+
$phpcsFile->addError($error, $stackPtr, 'MethodArguments');
294294
}
295295
}
296296

@@ -311,7 +311,7 @@ private function validateParameterPresentInMethodSignature(
311311
array $paramPointers
312312
): void {
313313
if (!in_array($paramDefinitionsArguments, $methodArguments)) {
314-
$phpcsFile->addFixableError(
314+
$phpcsFile->addError(
315315
$paramDefinitionsArguments . ' parameter is missing in method arguments signature',
316316
$paramPointers[$ptr],
317317
'MethodArguments'
@@ -340,7 +340,7 @@ private function validateParameterOrderIsCorrect(
340340
&& in_array($methodArguments[$ptr], $parameterNames)
341341
) {
342342
if ($methodArguments[$ptr] != $parameterNames[$ptr]) {
343-
$phpcsFile->addFixableError(
343+
$phpcsFile->addError(
344344
$methodArguments[$ptr] . ' parameter is not in order',
345345
$paramPointers[$ptr],
346346
'MethodArguments'
@@ -383,7 +383,7 @@ private function validateDuplicateAnnotationDoesnotExists(
383383
}
384384
}
385385
foreach ($duplicateParameters as $value) {
386-
$phpcsFile->addFixableError(
386+
$phpcsFile->addError(
387387
$value . ' duplicate found in method annotation',
388388
$stackPtr,
389389
'MethodArguments'
@@ -410,7 +410,7 @@ private function validateParameterAnnotationFormatIsCorrect(
410410
): void {
411411
switch (count($paramDefinitions)) {
412412
case 0:
413-
$phpcsFile->addFixableError(
413+
$phpcsFile->addError(
414414
'Missing both type and parameter',
415415
$paramPointers[$ptr],
416416
'MethodArguments'
@@ -427,7 +427,7 @@ private function validateParameterAnnotationFormatIsCorrect(
427427
break;
428428
case 2:
429429
if ($this->isInvalidType($paramDefinitions[0])) {
430-
$phpcsFile->addFixableError(
430+
$phpcsFile->addError(
431431
$paramDefinitions[0] . ' is not a valid PHP type',
432432
$paramPointers[$ptr],
433433
'MethodArguments'
@@ -449,7 +449,7 @@ private function validateParameterAnnotationFormatIsCorrect(
449449
'MethodArguments'
450450
);
451451
if ($this->isInvalidType($paramDefinitions[0])) {
452-
$phpcsFile->addFixableError(
452+
$phpcsFile->addError(
453453
$paramDefinitions[0] . ' is not a valid PHP type',
454454
$paramPointers[$ptr],
455455
'MethodArguments'
@@ -633,7 +633,7 @@ private function validateFormattingConsistency(
633633
}
634634
if (!$this->allParamsAligned($argumentPositions, $commentPositions)
635635
&& !$this->noneParamsAligned($argumentPositions, $commentPositions, $paramDefinitions)) {
636-
$phpcsFile->addFixableError(
636+
$phpcsFile->addError(
637637
'Method arguments visual alignment must be consistent',
638638
$paramPointers[0],
639639
'MethodArguments'

0 commit comments

Comments
 (0)