Skip to content

Commit

Permalink
Fixed bug #3672 : Incorrect ScopeIndent.IncorrectExact report for mat…
Browse files Browse the repository at this point in the history
…ch inside array literal
  • Loading branch information
gsherwood committed Sep 26, 2022
1 parent 7335f85 commit f1d1a68
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 13 deletions.
28 changes: 19 additions & 9 deletions src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,13 @@ public function process(File $phpcsFile, $stackPtr)
}
}

$lastOpenTag = $stackPtr;
$lastCloseTag = null;
$openScopes = [];
$adjustments = [];
$setIndents = [];
$disableExactEnd = 0;
$lastOpenTag = $stackPtr;
$lastCloseTag = null;
$openScopes = [];
$adjustments = [];
$setIndents = [];
$disableExactStack = [];
$disableExactEnd = 0;

$tokens = $phpcsFile->getTokens();
$first = $phpcsFile->findFirstOnLine(T_INLINE_HTML, $stackPtr);
Expand Down Expand Up @@ -223,6 +224,7 @@ public function process(File $phpcsFile, $stackPtr)
if ($tokens[$i]['code'] === T_OPEN_PARENTHESIS
&& isset($tokens[$i]['parenthesis_closer']) === true
) {
$disableExactStack[$tokens[$i]['parenthesis_closer']] = $tokens[$i]['parenthesis_closer'];
$disableExactEnd = max($disableExactEnd, $tokens[$i]['parenthesis_closer']);
if ($this->debug === true) {
$line = $tokens[$i]['line'];
Expand Down Expand Up @@ -686,9 +688,17 @@ public function process(File $phpcsFile, $stackPtr)
&& isset($tokens[$checkToken]['scope_opener']) === true
) {
$exact = true;

if ($disableExactEnd > $checkToken) {
if ($tokens[$checkToken]['conditions'] === $tokens[$disableExactEnd]['conditions']) {
$exact = false;
foreach ($disableExactStack as $disableExactStackEnd) {
if ($disableExactStackEnd < $checkToken) {
continue;
}

if ($tokens[$checkToken]['conditions'] === $tokens[$disableExactStackEnd]['conditions']) {
$exact = false;
break;
}
}
}

Expand Down Expand Up @@ -913,6 +923,7 @@ public function process(File $phpcsFile, $stackPtr)

// Don't check indents exactly between arrays as they tend to have custom rules.
if ($tokens[$i]['code'] === T_OPEN_SHORT_ARRAY) {
$disableExactStack[$tokens[$i]['bracket_closer']] = $tokens[$i]['bracket_closer'];
$disableExactEnd = max($disableExactEnd, $tokens[$i]['bracket_closer']);
if ($this->debug === true) {
$line = $tokens[$i]['line'];
Expand All @@ -934,7 +945,6 @@ public function process(File $phpcsFile, $stackPtr)
) {
if ($this->debug === true) {
$line = $tokens[$i]['line'];
$type = $tokens[$disableExactEnd]['type'];
Common::printStatusMessage("Here/nowdoc found on line $line");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,13 @@ switch ($foo) {
return 'default';
}

foo(function ($foo) {
return [
match ($foo) {
}
];
});

/* ADD NEW TESTS ABOVE THIS LINE AND MAKE SURE THAT THE 1 (space-based) AND 2 (tab-based) FILES ARE IN SYNC! */
?>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,13 @@ switch ($foo) {
return 'default';
}

foo(function ($foo) {
return [
match ($foo) {
}
];
});

/* ADD NEW TESTS ABOVE THIS LINE AND MAKE SURE THAT THE 1 (space-based) AND 2 (tab-based) FILES ARE IN SYNC! */
?>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,13 @@ switch ($foo) {
return 'default';
}

foo(function ($foo) {
return [
match ($foo) {
}
];
});

/* ADD NEW TESTS ABOVE THIS LINE AND MAKE SURE THAT THE 1 (space-based) AND 2 (tab-based) FILES ARE IN SYNC! */
?>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,13 @@ switch ($foo) {
return 'default';
}

foo(function ($foo) {
return [
match ($foo) {
}
];
});

/* ADD NEW TESTS ABOVE THIS LINE AND MAKE SURE THAT THE 1 (space-based) AND 2 (tab-based) FILES ARE IN SYNC! */
?>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ public function getErrorList($testFile='ScopeIndentUnitTest.inc')
1527 => 1,
1529 => 1,
1530 => 1,
1583 => 1,
1584 => 1,
1585 => 1,
1586 => 1,
1590 => 1,
1591 => 1,
1592 => 1,
1593 => 1,
];

}//end getErrorList()
Expand Down

0 comments on commit f1d1a68

Please sign in to comment.