Skip to content

Commit

Permalink
Fixed bug #2529 : Generic.Formatting.MultipleStatementAlignment wrong…
Browse files Browse the repository at this point in the history
… error for assign in string concat

Decided is was easiest to ignore assignment that are in parenthesis on the same line
  • Loading branch information
gsherwood committed Aug 9, 2019
1 parent 0278329 commit 8c31253
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #2526 : XML report format has bad syntax on Windows
-- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #2529 : Generic.Formatting.MultipleStatementAlignment wrong error for assign in string concat
- Fixed bug #2549 : Searching for a phpcs.xml file can throw warnings due to open_basedir restrictions
-- Thanks to Matthew Peveler for the patch
- Fixed bug #2558 : PHP 7.4 throwing offset syntax with curly braces is deprecated message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ public function process(File $phpcsFile, $stackPtr)

// Ignore assignments used in a condition, like an IF or FOR.
if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
// If the parenthesis is on the same line as the assignment,
// then it should be ignored as it is specifically being grouped.
$parens = $tokens[$stackPtr]['nested_parenthesis'];
$lastParen = array_pop($parens);
if ($tokens[$lastParen]['line'] === $tokens[$stackPtr]['line']) {
return;
}

foreach ($tokens[$stackPtr]['nested_parenthesis'] as $start => $end) {
if (isset($tokens[$start]['parenthesis_owner']) === true) {
return;
Expand Down Expand Up @@ -217,6 +225,14 @@ public function checkAlignment($phpcsFile, $stackPtr, $end=null)

// Make sure it is not assigned inside a condition (eg. IF, FOR).
if (isset($tokens[$assign]['nested_parenthesis']) === true) {
// If the parenthesis is on the same line as the assignment,
// then it should be ignored as it is specifically being grouped.
$parens = $tokens[$assign]['nested_parenthesis'];
$lastParen = array_pop($parens);
if ($tokens[$lastParen]['line'] === $tokens[$assign]['line']) {
break;
}

foreach ($tokens[$assign]['nested_parenthesis'] as $start => $end) {
if (isset($tokens[$start]['parenthesis_owner']) === true) {
break(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,6 @@ $foofoo = new Foo([
$b = new Bar(),
$c = new Bar(),
]);

$i = 0;
echo "TEST: ".($i += 1)."\n";
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,6 @@ $foofoo = new Foo([
$b = new Bar(),
$c = new Bar(),
]);

$i = 0;
echo "TEST: ".($i += 1)."\n";

0 comments on commit 8c31253

Please sign in to comment.