diff --git a/src/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php b/src/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php index 408856fc5a..1bf9444784 100644 --- a/src/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php +++ b/src/Standards/PEAR/Sniffs/Commenting/FunctionCommentSniff.php @@ -129,11 +129,25 @@ public function process(File $phpcsFile, $stackPtr) && $tokens[$i]['line'] !== $tokens[($i + 1)]['line'] ) { $error = 'There must be no blank lines after the function comment'; - $phpcsFile->addError($error, $commentEnd, 'SpacingAfter'); + $fix = $phpcsFile->addFixableError($error, $commentEnd, 'SpacingAfter'); + + if ($fix === true) { + $phpcsFile->fixer->beginChangeset(); + + while ($i < $stackPtr + && $tokens[$i]['code'] === T_WHITESPACE + && $tokens[$i]['line'] !== $tokens[($i + 1)]['line'] + ) { + $phpcsFile->fixer->replaceToken($i++, ''); + } + + $phpcsFile->fixer->endChangeset(); + } + break; } - } - } + }//end for + }//end if $commentStart = $tokens[$commentEnd]['comment_opener']; foreach ($tokens[$commentStart]['comment_tags'] as $tag) { diff --git a/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc b/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc index 5c3295fd60..a20ba3a720 100644 --- a/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc +++ b/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc @@ -476,3 +476,37 @@ class Something implements JsonSerializable { public function blankLineDetectionC() {} } + +class SpacingAfter { + /** + * There are multiple blank lines between this comment and the next function. + * + * @return void + */ + + + + + + + + + public function multipleBlankLines() {} + + /** + * There are multiple blank lines, and some "empty" lines with only + * spaces/tabs between this comment and the next function. + * + * @return void + */ + + + + + + + + + + public function multipleLinesSomeEmpty() {} +} diff --git a/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc.fixed b/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc.fixed index 751b09c665..fc6d4f7e71 100644 --- a/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc.fixed +++ b/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc.fixed @@ -453,7 +453,6 @@ class Something implements JsonSerializable { * * @return mixed */ - #[ReturnTypeWillChange] public function blankLineDetectionA() {} @@ -463,7 +462,6 @@ class Something implements JsonSerializable { * @return mixed */ #[ReturnTypeWillChange] - public function blankLineDetectionB() {} /** @@ -471,8 +469,23 @@ class Something implements JsonSerializable { * * @return mixed */ - #[ReturnTypeWillChange] - public function blankLineDetectionC() {} } + +class SpacingAfter { + /** + * There are multiple blank lines between this comment and the next function. + * + * @return void + */ + public function multipleBlankLines() {} + + /** + * There are multiple blank lines, and some "empty" lines with only + * spaces/tabs between this comment and the next function. + * + * @return void + */ + public function multipleLinesSomeEmpty() {} +} diff --git a/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.php b/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.php index 734ff73e50..e7ec800d02 100644 --- a/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.php +++ b/src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.php @@ -73,6 +73,8 @@ public function getErrorList() 455 => 1, 464 => 1, 473 => 1, + 485 => 1, + 501 => 1, ]; }//end getErrorList()