Skip to content

Commit 252d2f2

Browse files
committed
@phpcsSuppress can be with comment
1 parent e83970c commit 252d2f2

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

SlevomatCodingStandard/Helpers/SuppressHelper.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use SlevomatCodingStandard\Helpers\Annotation\Annotation;
77
use function array_reduce;
88
use function assert;
9+
use function explode;
910
use function sprintf;
1011
use function strpos;
1112
use const T_DOC_COMMENT_CLOSE_TAG;
@@ -24,9 +25,15 @@ public static function isSniffSuppressed(File $phpcsFile, int $pointer, string $
2425
return array_reduce(
2526
AnnotationHelper::getAnnotationsByName($phpcsFile, $pointer, self::ANNOTATION),
2627
static function (bool $carry, Annotation $annotation) use ($suppressName): bool {
28+
if ($annotation->getContent() === null) {
29+
return $carry;
30+
}
31+
32+
$annotationSuppressName = explode(' ', $annotation->getContent())[0];
33+
2734
if (
28-
$annotation->getContent() === $suppressName
29-
|| strpos($suppressName, sprintf('%s.', $annotation->getContent())) === 0
35+
$suppressName === $annotationSuppressName
36+
|| strpos($suppressName, sprintf('%s.', $annotationSuppressName)) === 0
3037
) {
3138
$carry = true;
3239
}

tests/Helpers/SuppressHelperTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public function dataFunctionIsSuppressed(): array
8686
return [
8787
['suppressWithFullName'],
8888
['suppressWithPartialName'],
89+
['suppressWithFullNameAndComment'],
90+
['suppressWithPartialNameAndComment'],
8991
['suppressWithFullDocComment'],
9092
];
9193
}

tests/Helpers/data/suppress.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ final public function suppressWithPartialName($e)
5454

5555
}
5656

57+
/**
58+
* @phpcsSuppress Sniff.Sniff.Sniff.check Some comment
59+
*/
60+
final public function suppressWithFullNameAndComment()
61+
{
62+
63+
}
64+
65+
/**
66+
* @phpcsSuppress Sniff.Sniff.Sniff Some comment
67+
*/
68+
final public function suppressWithPartialNameAndComment($e)
69+
{
70+
71+
}
72+
5773
/**
5874
* Description description description.
5975
*

0 commit comments

Comments
 (0)