Loading coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php +13 −2 Original line number Diff line number Diff line Loading @@ -92,7 +92,18 @@ class FunctionCommentSniff implements Sniff $find = Tokens::$methodPrefixes; $find[] = T_WHITESPACE; $beforeFunction = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true); if ($tokens[$beforeFunction]['code'] === T_ATTRIBUTE_END && $tokens[$tokens[$beforeFunction]['attribute_opener']]['code'] === T_ATTRIBUTE ) { // It's an attribute, such as #[\ReturnTypeWillChange]. $attributeLines = ($tokens[$beforeFunction]['line'] - $tokens[$tokens[$beforeFunction]['attribute_opener']]['line'] + 1); $commentEnd = $phpcsFile->findPrevious($find, ($tokens[$beforeFunction]['attribute_opener'] - 1), null, true); } else { $attributeLines = 0; $commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true); } $beforeCommentEnd = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($commentEnd - 1), null, true); if (($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG && $tokens[$commentEnd]['code'] !== T_COMMENT) Loading Loading @@ -151,7 +162,7 @@ class FunctionCommentSniff implements Sniff } }//end foreach if ($tokens[$commentEnd]['line'] !== ($tokens[$stackPtr]['line'] - 1)) { if ($tokens[$commentEnd]['line'] !== ($tokens[$stackPtr]['line'] - $attributeLines - 1)) { $error = 'There must be no blank lines after the function comment'; $fix = $phpcsFile->addFixableError($error, $commentEnd, 'SpacingAfter'); if ($fix === true) { Loading coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php +1 −0 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ class InlineCommentSniff implements Sniff ); $ignore = [ T_ATTRIBUTE, T_CLASS, T_INTERFACE, T_TRAIT, Loading tests/Drupal/good/good.php +14 −0 Original line number Diff line number Diff line Loading @@ -1800,3 +1800,17 @@ interface Test5Interface { public function test3(); } /** * Test PHP attributes. */ class TestPhpAttributes { /** * Tests method with PHP attribute and docblock. */ #[\ReturnTypeWillChange] public function attributes(): void { } } Loading
coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php +13 −2 Original line number Diff line number Diff line Loading @@ -92,7 +92,18 @@ class FunctionCommentSniff implements Sniff $find = Tokens::$methodPrefixes; $find[] = T_WHITESPACE; $beforeFunction = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true); if ($tokens[$beforeFunction]['code'] === T_ATTRIBUTE_END && $tokens[$tokens[$beforeFunction]['attribute_opener']]['code'] === T_ATTRIBUTE ) { // It's an attribute, such as #[\ReturnTypeWillChange]. $attributeLines = ($tokens[$beforeFunction]['line'] - $tokens[$tokens[$beforeFunction]['attribute_opener']]['line'] + 1); $commentEnd = $phpcsFile->findPrevious($find, ($tokens[$beforeFunction]['attribute_opener'] - 1), null, true); } else { $attributeLines = 0; $commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true); } $beforeCommentEnd = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($commentEnd - 1), null, true); if (($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG && $tokens[$commentEnd]['code'] !== T_COMMENT) Loading Loading @@ -151,7 +162,7 @@ class FunctionCommentSniff implements Sniff } }//end foreach if ($tokens[$commentEnd]['line'] !== ($tokens[$stackPtr]['line'] - 1)) { if ($tokens[$commentEnd]['line'] !== ($tokens[$stackPtr]['line'] - $attributeLines - 1)) { $error = 'There must be no blank lines after the function comment'; $fix = $phpcsFile->addFixableError($error, $commentEnd, 'SpacingAfter'); if ($fix === true) { Loading
coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php +1 −0 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ class InlineCommentSniff implements Sniff ); $ignore = [ T_ATTRIBUTE, T_CLASS, T_INTERFACE, T_TRAIT, Loading
tests/Drupal/good/good.php +14 −0 Original line number Diff line number Diff line Loading @@ -1800,3 +1800,17 @@ interface Test5Interface { public function test3(); } /** * Test PHP attributes. */ class TestPhpAttributes { /** * Tests method with PHP attribute and docblock. */ #[\ReturnTypeWillChange] public function attributes(): void { } }