Skip to content

Commit aebd84b

Browse files
authored
Squiz/FunctionSpacing: fixer is broken with doc comment on closing brace line (#784)
The fixer in Squiz.WhiteSpace.FunctionSpacing gets confused when there is a doc comment on the closing brace line. Generally speaking this sniff doesn't care about other content on the same line as the function declaration. But in the case of a "trailing" docblock, this meant that the sniff was adding the new lines _within_ the doc block, which, in turn, meant it would still not see the "blank lines after" in the next loop, as the added lines would be seen as doc comment lines, not blank lines. Hence, the fixer conflict. Fixed now.
1 parent ba08a82 commit aebd84b

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

src/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ public function process(File $phpcsFile, $stackPtr)
149149

150150
// Allow for comments on the same line as the closer.
151151
for ($nextLineToken = ($closer + 1); $nextLineToken < $phpcsFile->numTokens; $nextLineToken++) {
152+
// A doc comment belongs to the next statement and must not be on
153+
// this line.
154+
if ($tokens[$nextLineToken]['code'] === T_DOC_COMMENT_OPEN_TAG) {
155+
break;
156+
}
157+
152158
if ($tokens[$nextLineToken]['line'] !== $tokens[$closer]['line']) {
153159
break;
154160
}

src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,3 +582,14 @@ echo 'this line belongs with the #3904 test';
582582

583583
function Foo() {} function bar($name){}
584584
echo 'this line belongs with the #3904 test';
585+
586+
587+
/**
588+
* foo.
589+
*/
590+
function a() {
591+
}/**
592+
* foo.
593+
*/
594+
function b() {
595+
}

src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.1.inc.fixed

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,3 +671,17 @@ function Foo() {} function bar($name){}
671671

672672

673673
echo 'this line belongs with the #3904 test';
674+
675+
676+
/**
677+
* foo.
678+
*/
679+
function a() {
680+
}
681+
682+
683+
/**
684+
* foo.
685+
*/
686+
function b() {
687+
}

src/Standards/Squiz/Tests/WhiteSpace/FunctionSpacingUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public function getErrorList($testFile='')
102102
566 => 1,
103103
580 => 2,
104104
583 => 3,
105+
591 => 1,
105106
];
106107

107108
case 'FunctionSpacingUnitTest.2.inc':

0 commit comments

Comments
 (0)