diff --git a/package.xml b/package.xml index b4f36dc64c..fcdb419187 100644 --- a/package.xml +++ b/package.xml @@ -43,6 +43,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> - Fixed bug #2943 : Redundant semicolon added to a file when fixing PSR2.Files.ClosingTag.NotAllowed - Fixed bug #2977 : File::isReference() does not detect return by reference for closures -- Thanks to Juliette Reinders Folmer for the patch + - Fixed bug #2994 : Generic.Formatting.DisallowMultipleStatements false positive for FOR loop with no body diff --git a/src/Standards/Generic/Sniffs/Formatting/DisallowMultipleStatementsSniff.php b/src/Standards/Generic/Sniffs/Formatting/DisallowMultipleStatementsSniff.php index d67bb761e4..6f9ff9f917 100644 --- a/src/Standards/Generic/Sniffs/Formatting/DisallowMultipleStatementsSniff.php +++ b/src/Standards/Generic/Sniffs/Formatting/DisallowMultipleStatementsSniff.php @@ -59,16 +59,18 @@ public function process(File $phpcsFile, $stackPtr) } while ($tokens[$prev]['code'] === T_PHPCS_IGNORE); // Ignore multiple statements in a FOR condition. - if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) { - foreach ($tokens[$stackPtr]['nested_parenthesis'] as $bracket) { - if (isset($tokens[$bracket]['parenthesis_owner']) === false) { - // Probably a closure sitting inside a function call. - continue; - } - - $owner = $tokens[$bracket]['parenthesis_owner']; - if ($tokens[$owner]['code'] === T_FOR) { - return; + foreach ([$stackPtr, $prev] as $checkToken) { + if (isset($tokens[$checkToken]['nested_parenthesis']) === true) { + foreach ($tokens[$checkToken]['nested_parenthesis'] as $bracket) { + if (isset($tokens[$bracket]['parenthesis_owner']) === false) { + // Probably a closure sitting inside a function call. + continue; + } + + $owner = $tokens[$bracket]['parenthesis_owner']; + if ($tokens[$owner]['code'] === T_FOR) { + return; + } } } } diff --git a/src/Standards/Generic/Tests/Formatting/DisallowMultipleStatementsUnitTest.inc b/src/Standards/Generic/Tests/Formatting/DisallowMultipleStatementsUnitTest.inc index 5dd11cfdb7..ed316cc219 100644 --- a/src/Standards/Generic/Tests/Formatting/DisallowMultipleStatementsUnitTest.inc +++ b/src/Standards/Generic/Tests/Formatting/DisallowMultipleStatementsUnitTest.inc @@ -14,3 +14,7 @@ $this->wizardid = 10; $this->paint(); echo 'x';