diff --git a/package.xml b/package.xml index f2e54cfc1a..cfa256ab32 100644 --- a/package.xml +++ b/package.xml @@ -62,6 +62,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> -- Thanks to Juliette Reinders Folmer for the patch - Fixed bug #1840 : When a comment has too many asterisks, phpcbf gives FAILED TO FIX error - Fixed bug #1867 : Cant use phpcs:ignore where the next line is HTML + - Fixed bug #1870 : Invalid warning in multiple assignments alignment with closure or anon class diff --git a/src/Standards/Generic/Sniffs/Formatting/MultipleStatementAlignmentSniff.php b/src/Standards/Generic/Sniffs/Formatting/MultipleStatementAlignmentSniff.php index 29c5ae4e13..702f8425c3 100644 --- a/src/Standards/Generic/Sniffs/Formatting/MultipleStatementAlignmentSniff.php +++ b/src/Standards/Generic/Sniffs/Formatting/MultipleStatementAlignmentSniff.php @@ -116,6 +116,14 @@ public function checkAlignment($phpcsFile, $stackPtr) for ($assign = $stackPtr; $assign < $phpcsFile->numTokens; $assign++) { if (isset($find[$tokens[$assign]['code']]) === false) { + if ($tokens[$assign]['code'] === T_CLOSURE + || $tokens[$assign]['code'] === T_ANON_CLASS + ) { + $assign = $tokens[$assign]['scope_closer']; + $lastCode = $assign; + continue; + } + // A blank line indicates that the assignment block has ended. if (isset(Tokens::$emptyTokens[$tokens[$assign]['code']]) === false) { if (($tokens[$assign]['line'] - $tokens[$lastCode]['line']) > 1) { diff --git a/src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.inc b/src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.inc index 4455a53c67..2c4d1d9690 100644 --- a/src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.inc +++ b/src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.inc @@ -232,3 +232,19 @@ $bar = 'hi'; $foo = $moo = $test; $boo = 'boo'; $foo = $moooo = 'foo'; + +$foobarbaz = array_map( + function ($n) { + return $n * $n; + }, + [1, 2, 3] +); +$foo = 5; + +$loggerResult = $util->setLogger(new class { + public function log($msg) + { + echo $msg; + } +}); +$foo = 5; diff --git a/src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.inc.fixed b/src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.inc.fixed index 17ce2df1d1..a414878226 100644 --- a/src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.inc.fixed +++ b/src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.inc.fixed @@ -232,3 +232,19 @@ $bar = 'hi'; $foo = $moo = $test; $boo = 'boo'; $foo = $moooo = 'foo'; + +$foobarbaz = array_map( + function ($n) { + return $n * $n; + }, + [1, 2, 3] +); +$foo = 5; + +$loggerResult = $util->setLogger(new class { + public function log($msg) + { + echo $msg; + } +}); +$foo = 5;