Skip to content

Commit f636fe5

Browse files
committed
fix(FunctionSpacing): Fixer is broken with doc comment on closing brace line
1 parent ba08a82 commit f636fe5

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ 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+
}
152157
if ($tokens[$nextLineToken]['line'] !== $tokens[$closer]['line']) {
153158
break;
154159
}

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)