Skip to content

Commit 0434c48

Browse files
committed
Fixed bug #893 : Squiz.WhiteSpace.MemberVarSpacing.AfterComment fails to fix error when comment is not a docblock
1 parent e2e4756 commit 0434c48

File tree

5 files changed

+15
-0
lines changed

5 files changed

+15
-0
lines changed

CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
6363
$fix = $phpcsFile->addFixableError($error, $prev, 'AfterComment', $data);
6464
if ($fix === true) {
6565
$phpcsFile->fixer->beginChangeset();
66+
// Inline comments have the newline included in the content but
67+
// docblock do not.
68+
if ($tokens[$prev]['code'] === T_COMMENT) {
69+
$phpcsFile->fixer->replaceToken($prev, rtrim($tokens[$prev]['content']));
70+
}
71+
6672
for ($i = ($prev + 1); $i <= $stackPtr; $i++) {
6773
if ($tokens[$i]['line'] === $tokens[$stackPtr]['line']) {
6874
break;

CodeSniffer/Standards/Squiz/Tests/WhiteSpace/MemberVarSpacingUnitTest.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,8 @@ class Foo
147147

148148
private $bar;
149149

150+
// here comes the comment
151+
152+
private $caseStudy = null;
153+
150154
}

CodeSniffer/Standards/Squiz/Tests/WhiteSpace/MemberVarSpacingUnitTest.inc.fixed

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,7 @@ class Foo
146146

147147
private $bar;
148148

149+
// here comes the comment
150+
private $caseStudy = null;
151+
149152
}

CodeSniffer/Standards/Squiz/Tests/WhiteSpace/MemberVarSpacingUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function getErrorList()
5454
86 => 1,
5555
106 => 1,
5656
115 => 1,
57+
150 => 1,
5758
);
5859

5960
}//end getErrorList()

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
4646
- Fixed bug #973 : Anonymous class declaration and PSR1.Files.SideEffects.FoundWithSymbols
4747
- Fixed bug #974 : Error when file ends with "function"
4848
- Fixed bug #979 : Anonymous function with return type hint is not refactored as expected
49+
- Fixed bug #893 : Squiz.WhiteSpace.MemberVarSpacing.AfterComment fails to fix error when comment is not a docblock
4950
</notes>
5051
<contents>
5152
<dir name="/">

0 commit comments

Comments
 (0)