Skip to content

Commit

Permalink
Fixed bug #3219 : Generic.Formatting.MultipleStatementAlignment false…
Browse files Browse the repository at this point in the history
… positive for empty anonymous classes and closures
  • Loading branch information
gsherwood committed Feb 14, 2021
1 parent ea8158c commit 2ba5393
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #3192 : findStartOfStatement doesn't work correctly inside switch
-- Thanks to Vincent Langlet for the patch
- Fixed bug #3197 : Squiz.NamingConventions.ValidVariableName does not use correct error code for all member vars
- Fixed bug #3219 : Generic.Formatting.MultipleStatementAlignment false positive for empty anonymous classes and closures
</notes>
<contents>
<dir name="/">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,25 @@ public function checkAlignment($phpcsFile, $stackPtr, $end=null)
break;
}

if (isset($scopes[$tokens[$assign]['code']]) === true
&& isset($tokens[$assign]['scope_opener']) === true
if (isset($tokens[$assign]['scope_opener']) === true
&& $tokens[$assign]['level'] === $tokens[$stackPtr]['level']
) {
break;
if (isset($scopes[$tokens[$assign]['code']]) === true) {
// This type of scope indicates that the assignment block is over.
break;
}

// Skip over the scope block because it is seen as part of the assignment block,
// but also process any assignment blocks that are inside as well.
$nextAssign = $phpcsFile->findNext($find, ($assign + 1), ($tokens[$assign]['scope_closer'] - 1));
if ($nextAssign !== false) {
$assign = $this->checkAlignment($phpcsFile, $nextAssign);
} else {
$assign = $tokens[$assign]['scope_closer'];
}

$lastCode = $assign;
continue;
}

if ($assign === $arrayEnd) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,17 @@ $varonetwothreefour = 'four';
$one <<= 8;
$onetwothree = 3;

// phpcs:set Generic.Formatting.MultipleStatementAlignment maxPadding 1000

$a = 123;
$model = new class() {
// empty
};
$resource = new class() {
// empty
};

// phpcs:set Generic.Formatting.MultipleStatementAlignment alignAtEnd true

$one <<= 8;
$onetwothree = 3;

// phpcs:set Generic.Formatting.MultipleStatementAlignment maxPadding 1000
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,17 @@ $varonetwothreefour = 'four';
$one <<= 8;
$onetwothree = 3;

// phpcs:set Generic.Formatting.MultipleStatementAlignment maxPadding 1000

$a = 123;
$model = new class() {
// empty
};
$resource = new class() {
// empty
};

// phpcs:set Generic.Formatting.MultipleStatementAlignment alignAtEnd true

$one <<= 8;
$onetwothree = 3;

// phpcs:set Generic.Formatting.MultipleStatementAlignment maxPadding 1000

0 comments on commit 2ba5393

Please sign in to comment.