Skip to content

Commit 0e947f9

Browse files
committed
Fixed bug #564 : Generic MultipleStatementAlignment sniff reports incorrect errors for multiple assignments on a single line
1 parent 00e69ca commit 0e947f9

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

CodeSniffer/Standards/Generic/Sniffs/Formatting/MultipleStatementAlignmentSniff.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ public function checkAlignment(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
150150
}
151151
}//end if
152152

153+
continue;
154+
} else if ($assign !== $stackPtr && $tokens[$assign]['line'] === $lastLine) {
155+
// Skip multiple assignments on the same line. We only need to
156+
// try and align the first assignment.
153157
continue;
154158
}//end if
155159

CodeSniffer/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,8 @@ $path .= FileSystem::getHashDir($itemid).'/'.$itemid;
227227

228228
$contents .= 'if (';
229229
$conditions = array();
230+
231+
$bar = 'hi';
232+
$foo = $moo = $test;
233+
$boo = 'boo';
234+
$foo = $moooo = 'foo';

CodeSniffer/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.inc.fixed

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,8 @@ $path .= FileSystem::getHashDir($itemid).'/'.$itemid;
227227

228228
$contents .= 'if (';
229229
$conditions = array();
230+
231+
$bar = 'hi';
232+
$foo = $moo = $test;
233+
$boo = 'boo';
234+
$foo = $moooo = 'foo';

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
5050
- Fixed bug #551 : Multiple catch blocks not checked in Squiz.ControlStructures.ControlSignature sniff
5151
- Fixed bug #554 : ScopeIndentSniff causes errors when encountering an unmatched parenthesis
5252
- Fixed bug #558 : PHPCBF adds brace for ELSE IF split over multiple lines
53+
- Fixed bug #564 : Generic MultipleStatementAlignment sniff reports incorrect errors for multiple assignments on a single line
5354
</notes>
5455
<contents>
5556
<dir name="/">

0 commit comments

Comments
 (0)