Skip to content

Commit

Permalink
Added attribute support
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Mar 30, 2021
1 parent 158ea91 commit 6da6d82
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.4.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.5.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.6.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.7.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.1.js" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.1.js.fixed" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileCommentUnitTest.2.js" role="test" />
Expand Down
24 changes: 18 additions & 6 deletions src/Standards/Squiz/Sniffs/Commenting/FileCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,24 @@ public function process(File $phpcsFile, $stackPtr)

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

$nextToken = $phpcsFile->findNext(
T_WHITESPACE,
($commentEnd + 1),
null,
true
);
for ($nextToken = ($commentEnd + 1); $nextToken < $phpcsFile->numTokens; $nextToken++) {
if ($tokens[$nextToken]['code'] === T_WHITESPACE) {
continue;
}

if ($tokens[$nextToken]['code'] === T_ATTRIBUTE
&& isset($tokens[$nextToken]['attribute_closer']) === true
) {
$nextToken = $tokens[$nextToken]['attribute_closer'];
continue;
}

break;
}

if ($nextToken === $phpcsFile->numTokens) {
$nextToken--;
}

$ignore = [
T_CLASS,
Expand Down
12 changes: 12 additions & 0 deletions src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.7.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* This should not be recognized as a file comment, but as a class comment.
*
* @package Package
* @subpackage Subpackage
* @author Squiz Pty Ltd <products@squiz.net>
* @copyright 2010-2014 Squiz Pty Ltd (ABN 77 084 670 600)
*/
#[Attribute]
class Foo {
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function getErrorList($testFile='FileCommentUnitTest.inc')

case 'FileCommentUnitTest.4.inc':
case 'FileCommentUnitTest.6.inc':
case 'FileCommentUnitTest.7.inc':
return [1 => 1];

case 'FileCommentUnitTest.5.inc':
Expand Down

0 comments on commit 6da6d82

Please sign in to comment.