From 6da6d82e485902a27558eab1be5275a21654ebfe Mon Sep 17 00:00:00 2001 From: Greg Sherwood Date: Wed, 31 Mar 2021 10:14:16 +1100 Subject: [PATCH] Added attribute support --- package.xml | 1 + .../Sniffs/Commenting/FileCommentSniff.php | 24 ++++++++++++++----- .../Commenting/FileCommentUnitTest.7.inc | 12 ++++++++++ .../Tests/Commenting/FileCommentUnitTest.php | 1 + 4 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.7.inc diff --git a/package.xml b/package.xml index 0e7896fdca..ce352c57fd 100644 --- a/package.xml +++ b/package.xml @@ -1687,6 +1687,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + diff --git a/src/Standards/Squiz/Sniffs/Commenting/FileCommentSniff.php b/src/Standards/Squiz/Sniffs/Commenting/FileCommentSniff.php index 66fc5e4db1..73eb31b71f 100644 --- a/src/Standards/Squiz/Sniffs/Commenting/FileCommentSniff.php +++ b/src/Standards/Squiz/Sniffs/Commenting/FileCommentSniff.php @@ -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, diff --git a/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.7.inc b/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.7.inc new file mode 100644 index 0000000000..7074dac234 --- /dev/null +++ b/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.7.inc @@ -0,0 +1,12 @@ + + * @copyright 2010-2014 Squiz Pty Ltd (ABN 77 084 670 600) + */ +#[Attribute] +class Foo { +} diff --git a/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.php b/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.php index b3708e80cf..080df3aafc 100644 --- a/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.php +++ b/src/Standards/Squiz/Tests/Commenting/FileCommentUnitTest.php @@ -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':