Skip to content

Commit cf10256

Browse files
committed
SlevomatCodingStandard.Commenting.AnnotationName: Fixed false positives
1 parent 710c256 commit cf10256

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

SlevomatCodingStandard/Sniffs/Commenting/AnnotationNameSniff.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PHP_CodeSniffer\Sniffs\Sniff;
77
use SlevomatCodingStandard\Helpers\AnnotationHelper;
88
use SlevomatCodingStandard\Helpers\FixerHelper;
9+
use SlevomatCodingStandard\Helpers\NamespaceHelper;
910
use SlevomatCodingStandard\Helpers\SniffSettingsHelper;
1011
use SlevomatCodingStandard\Helpers\TokenHelper;
1112
use function array_combine;
@@ -184,6 +185,17 @@ public function process(File $phpcsFile, $docCommentOpenPointer): void
184185
}
185186

186187
foreach ($annotationsByName as $annotation) {
188+
$annotationNameWithoutAtSign = ltrim($annotationName, '@');
189+
$fullyQualifiedAnnotationName = NamespaceHelper::resolveClassName(
190+
$phpcsFile,
191+
$annotationNameWithoutAtSign,
192+
$annotation->getStartPointer()
193+
);
194+
195+
if (NamespaceHelper::normalizeToCanonicalName($fullyQualifiedAnnotationName) !== $annotationNameWithoutAtSign) {
196+
continue;
197+
}
198+
187199
$fix = $phpcsFile->addFixableError(
188200
sprintf('Annotation name is incorrect. Expected %s, found %s.', $correctAnnotationName, $annotationName),
189201
$annotation->getStartPointer(),

tests/Sniffs/Commenting/data/annotationNameNoErrors.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Something\Before;
4+
35
/**
46
* @deprecated
57
*
@@ -17,6 +19,8 @@ public function method($a)
1719
}
1820

1921
/**
22+
* @Before
23+
*
2024
* @inheritDoc
2125
*
2226
* And some text with {@inheritDoc} annotation.

0 commit comments

Comments
 (0)