Skip to content

Commit a30addb

Browse files
rodrigoprimojrfnl
authored andcommitted
Generic/IncrementDecrementSpacing: fix post-decrement error message
This commit fixes the post-decrement error message when there is one or more newlines between the variable and the post-decrement operator. The wrong variable was being used to check whether the post-decrement and the variable were not on the same line, resulting in an incorrect error message. The error message should explicitly say that a newline was found. Before this commit the error message was: ``` Expected no spaces between $i and the decrement operator; 0 found ``` Now it is: ``` Expected no spaces between the decrement operator and $i; newline found ``` (`newline` instead of `0`) This commit also includes a test that exercises the modified line.
1 parent b03d10f commit a30addb

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

src/Standards/Generic/Sniffs/WhiteSpace/IncrementDecrementSpacingSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function process(File $phpcsFile, $stackPtr)
135135
$fixable = false;
136136
$spaces = 'comment';
137137
} else {
138-
if ($tokens[$stackPtr]['line'] !== $tokens[$nextNonEmpty]['line']) {
138+
if ($tokens[$stackPtr]['line'] !== $tokens[$prevNonEmpty]['line']) {
139139
$spaces = 'newline';
140140
} else {
141141
$spaces = $tokens[($stackPtr - 1)]['length'];

src/Standards/Generic/Tests/WhiteSpace/IncrementDecrementSpacingUnitTest.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ $obj->prop['key'] ++;
3535

3636
--ClassName::$prop;
3737
-- ClassName::$prop;
38+
39+
getObject()->count
40+
++;

src/Standards/Generic/Tests/WhiteSpace/IncrementDecrementSpacingUnitTest.inc.fixed

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ $obj->prop['key']++;
3434

3535
--ClassName::$prop;
3636
--ClassName::$prop;
37+
38+
getObject()->count++;

src/Standards/Generic/Tests/WhiteSpace/IncrementDecrementSpacingUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function getErrorList($testFile='')
5353
$errors[31] = 1;
5454
$errors[34] = 1;
5555
$errors[37] = 1;
56+
$errors[40] = 1;
5657

5758
return $errors;
5859

0 commit comments

Comments
 (0)