diff --git a/src/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php b/src/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php index 01cbd647f7..c0cbed2268 100644 --- a/src/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php +++ b/src/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php @@ -149,6 +149,12 @@ public function process(File $phpcsFile, $stackPtr) // Allow for comments on the same line as the closer. for ($nextLineToken = ($closer + 1); $nextLineToken < $phpcsFile->numTokens; $nextLineToken++) { + // A doc comment belongs to the next statement and must not be on + // this line. + if ($tokens[$nextLineToken]['code'] === T_DOC_COMMENT_OPEN_TAG) { + break; + } + if ($tokens[$nextLineToken]['line'] !== $tokens[$closer]['line']) { break; } diff --git a/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc b/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc index b03a0ed82c..581235e14c 100644 --- a/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc +++ b/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc @@ -582,3 +582,14 @@ echo 'this line belongs with the #3904 test'; function Foo() {} function bar($name){} echo 'this line belongs with the #3904 test'; + + +/** + * foo. + */ +function a() { +}/** + * foo. + */ +function b() { +} diff --git a/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc.fixed b/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc.fixed index 443824ca14..f1b979326a 100644 --- a/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc.fixed +++ b/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc.fixed @@ -671,3 +671,17 @@ function Foo() {} function bar($name){} echo 'this line belongs with the #3904 test'; + + +/** + * foo. + */ +function a() { +} + + +/** + * foo. + */ +function b() { +} diff --git a/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.php b/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.php index cc6d96d256..17c431ee4b 100644 --- a/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.php +++ b/src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.php @@ -102,6 +102,7 @@ public function getErrorList($testFile='') 566 => 1, 580 => 2, 583 => 3, + 591 => 1, ]; case 'FunctionSpacingUnitTest.2.inc':