Skip to content

Commit

Permalink
Fixed bug #2702 : Generic.WhiteSpace.ScopeIndent false positive when …
Browse files Browse the repository at this point in the history
…using ternary operator with short arrays

The first token was being recalculated but the indent was not being modified along with that new first token.
  • Loading branch information
gsherwood committed Nov 18, 2019
1 parent c120776 commit eb378ac
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 10 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #2694 : AbstractArraySniff produces invalid indices when using ternary operator
-- Thanks to Michał Bundyra for the patch
- Fixed bug #2702 : Generic.WhiteSpace.ScopeIndent false positive when using ternary operator with short arrays
</notes>
<contents>
<dir name="/">
Expand Down
12 changes: 6 additions & 6 deletions src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,7 @@ public function process(File $phpcsFile, $stackPtr)

$arrayOpener = $tokens[$arrayCloser]['bracket_opener'];
if ($tokens[$arrayCloser]['line'] !== $tokens[$arrayOpener]['line']) {
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $arrayOpener, true);
$checkIndent = ($tokens[$first]['column'] - 1);
if (isset($adjustments[$first]) === true) {
$checkIndent += $adjustments[$first];
}

$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $arrayOpener, true);
$exact = false;

if ($this->debug === true) {
Expand Down Expand Up @@ -524,6 +519,11 @@ public function process(File $phpcsFile, $stackPtr)
$first = $phpcsFile->findNext(T_WHITESPACE, ($first + 1), null, true);
}

$checkIndent = ($tokens[$first]['column'] - 1);
if (isset($adjustments[$first]) === true) {
$checkIndent += $adjustments[$first];
}

if (isset($tokens[$first]['scope_closer']) === true
&& $tokens[$first]['scope_closer'] === $first
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,12 @@ $result = array_map(
$numbers
);

$a = $a === true ? [
'a' => 1,
] : [
'a' => 100,
];

?>

<?php if (true) : ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,12 @@ $result = array_map(
$numbers
);

$a = $a === true ? [
'a' => 1,
] : [
'a' => 100,
];

?>

<?php if (true) : ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,12 @@ $result = array_map(
$numbers
);

$a = $a === true ? [
'a' => 1,
] : [
'a' => 100,
];

?>

<?php if (true) : ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,12 @@ $result = array_map(
$numbers
);

$a = $a === true ? [
'a' => 1,
] : [
'a' => 100,
];

?>

<?php if (true) : ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ public function getErrorList($testFile='ScopeIndentUnitTest.inc')
1340 => 1,
1342 => 1,
1345 => 1,
1449 => 1,
1450 => 1,
1451 => 1,
1452 => 1,
1455 => 1,
1456 => 1,
1457 => 1,
1458 => 1,
];

}//end getErrorList()
Expand Down

0 comments on commit eb378ac

Please sign in to comment.