Skip to content

Commit eb378ac

Browse files
committed
Fixed bug #2702 : Generic.WhiteSpace.ScopeIndent false positive when 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.
1 parent c120776 commit eb378ac

File tree

7 files changed

+35
-10
lines changed

7 files changed

+35
-10
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
6666
-- Thanks to Juliette Reinders Folmer for the patch
6767
- Fixed bug #2694 : AbstractArraySniff produces invalid indices when using ternary operator
6868
-- Thanks to Michał Bundyra for the patch
69+
- Fixed bug #2702 : Generic.WhiteSpace.ScopeIndent false positive when using ternary operator with short arrays
6970
</notes>
7071
<contents>
7172
<dir name="/">

src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -483,12 +483,7 @@ public function process(File $phpcsFile, $stackPtr)
483483

484484
$arrayOpener = $tokens[$arrayCloser]['bracket_opener'];
485485
if ($tokens[$arrayCloser]['line'] !== $tokens[$arrayOpener]['line']) {
486-
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $arrayOpener, true);
487-
$checkIndent = ($tokens[$first]['column'] - 1);
488-
if (isset($adjustments[$first]) === true) {
489-
$checkIndent += $adjustments[$first];
490-
}
491-
486+
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $arrayOpener, true);
492487
$exact = false;
493488

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

522+
$checkIndent = ($tokens[$first]['column'] - 1);
523+
if (isset($adjustments[$first]) === true) {
524+
$checkIndent += $adjustments[$first];
525+
}
526+
527527
if (isset($tokens[$first]['scope_closer']) === true
528528
&& $tokens[$first]['scope_closer'] === $first
529529
) {

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,12 @@ $result = array_map(
14391439
$numbers
14401440
);
14411441

1442+
$a = $a === true ? [
1443+
'a' => 1,
1444+
] : [
1445+
'a' => 100,
1446+
];
1447+
14421448
?>
14431449

14441450
<?php if (true) : ?>

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.1.inc.fixed

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,12 @@ $result = array_map(
14391439
$numbers
14401440
);
14411441

1442+
$a = $a === true ? [
1443+
'a' => 1,
1444+
] : [
1445+
'a' => 100,
1446+
];
1447+
14421448
?>
14431449

14441450
<?php if (true) : ?>

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,12 @@ $result = array_map(
14391439
$numbers
14401440
);
14411441

1442+
$a = $a === true ? [
1443+
'a' => 1,
1444+
] : [
1445+
'a' => 100,
1446+
];
1447+
14421448
?>
14431449

14441450
<?php if (true) : ?>

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.2.inc.fixed

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,12 @@ $result = array_map(
14391439
$numbers
14401440
);
14411441

1442+
$a = $a === true ? [
1443+
'a' => 1,
1444+
] : [
1445+
'a' => 100,
1446+
];
1447+
14421448
?>
14431449

14441450
<?php if (true) : ?>

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ public function getErrorList($testFile='ScopeIndentUnitTest.inc')
178178
1340 => 1,
179179
1342 => 1,
180180
1345 => 1,
181-
1449 => 1,
182-
1450 => 1,
183-
1451 => 1,
184-
1452 => 1,
181+
1455 => 1,
182+
1456 => 1,
183+
1457 => 1,
184+
1458 => 1,
185185
];
186186

187187
}//end getErrorList()

0 commit comments

Comments
 (0)