Skip to content

Commit 6da6d82

Browse files
committed
Added attribute support
1 parent 158ea91 commit 6da6d82

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,6 +1687,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
16871687
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.4.inc" role="test" />
16881688
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.5.inc" role="test" />
16891689
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.6.inc" role="test" />
1690+
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.7.inc" role="test" />
16901691
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.1.js" role="test" />
16911692
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.1.js.fixed" role="test" />
16921693
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.2.js" role="test" />

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,24 @@ public function process(File $phpcsFile, $stackPtr)
7272

7373
$commentEnd = $tokens[$commentStart]['comment_closer'];
7474

75-
$nextToken = $phpcsFile->findNext(
76-
T_WHITESPACE,
77-
($commentEnd + 1),
78-
null,
79-
true
80-
);
75+
for ($nextToken = ($commentEnd + 1); $nextToken < $phpcsFile->numTokens; $nextToken++) {
76+
if ($tokens[$nextToken]['code'] === T_WHITESPACE) {
77+
continue;
78+
}
79+
80+
if ($tokens[$nextToken]['code'] === T_ATTRIBUTE
81+
&& isset($tokens[$nextToken]['attribute_closer']) === true
82+
) {
83+
$nextToken = $tokens[$nextToken]['attribute_closer'];
84+
continue;
85+
}
86+
87+
break;
88+
}
89+
90+
if ($nextToken === $phpcsFile->numTokens) {
91+
$nextToken--;
92+
}
8193

8294
$ignore = [
8395
T_CLASS,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* This should not be recognized as a file comment, but as a class comment.
4+
*
5+
* @package Package
6+
* @subpackage Subpackage
7+
* @author Squiz Pty Ltd <[email protected]>
8+
* @copyright 2010-2014 Squiz Pty Ltd (ABN 77 084 670 600)
9+
*/
10+
#[Attribute]
11+
class Foo {
12+
}

src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function getErrorList($testFile='FileCommentUnitTest.inc')
4444

4545
case 'FileCommentUnitTest.4.inc':
4646
case 'FileCommentUnitTest.6.inc':
47+
case 'FileCommentUnitTest.7.inc':
4748
return [1 => 1];
4849

4950
case 'FileCommentUnitTest.5.inc':

0 commit comments

Comments
 (0)