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 65330c5 commit e0ffb0f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
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 e0ffb0f

Please sign in to comment.