Skip to content

Commit

Permalink
Fixed bug #2994 : Generic.Formatting.DisallowMultipleStatements false…
Browse files Browse the repository at this point in the history
… positive for FOR loop with no body
  • Loading branch information
gsherwood committed Jul 22, 2020
1 parent e3eecbb commit ea2cf3f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
</notes>
<contents>
<dir name="/">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ $this->wizardid = 10; $this->paint(); echo 'x';

<?php
echo 'x'; /* phpcs:ignore Standard */ echo $y; /* phpcs:ignore OtherStandard */;

for ($i = 0 ; $i < 10; $i++);
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ echo 'x';

<?php
echo 'x'; /* phpcs:ignore Standard */ echo $y; /* phpcs:ignore OtherStandard */;

for ($i = 0 ; $i < 10; $i++);
{
}

0 comments on commit ea2cf3f

Please sign in to comment.