Skip to content

Commit bc882d4

Browse files
committed
Added attribute support
1 parent c132dc5 commit bc882d4

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/Standards/Squiz/Sniffs/Commenting/ClassCommentSniff.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,28 @@ public function process(File $phpcsFile, $stackPtr)
5050
{
5151
$tokens = $phpcsFile->getTokens();
5252
$find = Tokens::$methodPrefixes;
53-
$find[] = T_WHITESPACE;
53+
$find[T_WHITESPACE] = T_WHITESPACE;
54+
55+
$previousContent = null;
56+
for ($commentEnd = ($stackPtr - 1); $commentEnd >= 0; $commentEnd--) {
57+
if (isset($find[$tokens[$commentEnd]['code']]) === true) {
58+
continue;
59+
}
60+
61+
if ($previousContent === null) {
62+
$previousContent = $commentEnd;
63+
}
64+
65+
if ($tokens[$commentEnd]['code'] === T_ATTRIBUTE_END
66+
&& isset($tokens[$commentEnd]['attribute_opener']) === true
67+
) {
68+
$commentEnd = $tokens[$commentEnd]['attribute_opener'];
69+
continue;
70+
}
71+
72+
break;
73+
}
5474

55-
$commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true);
5675
if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG
5776
&& $tokens[$commentEnd]['code'] !== T_COMMENT
5877
) {
@@ -69,7 +88,7 @@ public function process(File $phpcsFile, $stackPtr)
6988
return;
7089
}
7190

72-
if ($tokens[$commentEnd]['line'] !== ($tokens[$stackPtr]['line'] - 1)) {
91+
if ($tokens[$previousContent]['line'] !== ($tokens[$stackPtr]['line'] - 1)) {
7392
$error = 'There must be no blank lines after the class comment';
7493
$phpcsFile->addError($error, $commentEnd, 'SpacingAfter');
7594
}

src/Standards/Squiz/Tests/Commenting/ClassCommentUnitTest.inc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,11 @@ class Space_At_end
123123
{
124124

125125
}//end class
126+
127+
/**
128+
* Sample class comment
129+
*/
130+
#[Attribute]
131+
class AllGood
132+
{
133+
}

0 commit comments

Comments
 (0)