Skip to content

Commit 8421eeb

Browse files
committed
Fixed bug #2913 : Generic.WhiteSpace.ScopeIndent false positive when opening and closing tag on same line inside conditional
1 parent 99b0339 commit 8421eeb

File tree

7 files changed

+37
-5
lines changed

7 files changed

+37
-5
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
6161
- Fixed an issue that could occurr when checking files on network drives, such as with WSL2 on Windows 10
6262
-- This works around a long-standing PHP bug with is_readable()
6363
-- Thanks to Michael S for the patch
64+
- Fixed bug #2913 : Generic.WhiteSpace.ScopeIndent false positive when opening and closing tag on same line inside conditional
6465
- Fixed bug #3157 : PSR2.ControlStructures.SwitchDeclaration.BreakIndent false positive when case keyword is not indented
6566
</notes>
6667
<contents>

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,14 @@ public function process(File $phpcsFile, $stackPtr)
337337
echo "\t* open tag is inside condition; using open tag *".PHP_EOL;
338338
}
339339

340-
$checkIndent = ($tokens[$lastOpenTag]['column'] - 1);
340+
$first = $phpcsFile->findFirstOnLine([T_WHITESPACE, T_INLINE_HTML], $lastOpenTag, true);
341+
if ($this->debug === true) {
342+
$line = $tokens[$first]['line'];
343+
$type = $tokens[$first]['type'];
344+
echo "\t* first token on line $line is $first ($type) *".PHP_EOL;
345+
}
346+
347+
$checkIndent = ($tokens[$first]['column'] - 1);
341348
if (isset($adjustments[$condition]) === true) {
342349
$checkIndent += $adjustments[$condition];
343350
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,12 @@ echo $string?->append('foo')
14621462
?->outputUsing();
14631463
// phpcs:set Generic.WhiteSpace.ScopeIndent exact false
14641464

1465+
if (true) {
1466+
?><?php echo addslashes(
1467+
''
1468+
)?><?php
1469+
}
1470+
14651471
/* ADD NEW TESTS ABOVE THIS LINE AND MAKE SURE THAT THE 1 (space-based) AND 2 (tab-based) FILES ARE IN SYNC! */
14661472
?>
14671473

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,12 @@ echo $string?->append('foo')
14621462
?->outputUsing();
14631463
// phpcs:set Generic.WhiteSpace.ScopeIndent exact false
14641464

1465+
if (true) {
1466+
?><?php echo addslashes(
1467+
''
1468+
)?><?php
1469+
}
1470+
14651471
/* ADD NEW TESTS ABOVE THIS LINE AND MAKE SURE THAT THE 1 (space-based) AND 2 (tab-based) FILES ARE IN SYNC! */
14661472
?>
14671473

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,12 @@ echo $string?->append('foo')
14621462
?->outputUsing();
14631463
// phpcs:set Generic.WhiteSpace.ScopeIndent exact false
14641464

1465+
if (true) {
1466+
?><?php echo addslashes(
1467+
''
1468+
)?><?php
1469+
}
1470+
14651471
/* ADD NEW TESTS ABOVE THIS LINE AND MAKE SURE THAT THE 1 (space-based) AND 2 (tab-based) FILES ARE IN SYNC! */
14661472
?>
14671473

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,12 @@ echo $string?->append('foo')
14621462
?->outputUsing();
14631463
// phpcs:set Generic.WhiteSpace.ScopeIndent exact false
14641464

1465+
if (true) {
1466+
?><?php echo addslashes(
1467+
''
1468+
)?><?php
1469+
}
1470+
14651471
/* ADD NEW TESTS ABOVE THIS LINE AND MAKE SURE THAT THE 1 (space-based) AND 2 (tab-based) FILES ARE IN SYNC! */
14661472
?>
14671473

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-
1473 => 1,
182-
1474 => 1,
183-
1475 => 1,
184-
1476 => 1,
181+
1479 => 1,
182+
1480 => 1,
183+
1481 => 1,
184+
1482 => 1,
185185
];
186186

187187
}//end getErrorList()

0 commit comments

Comments
 (0)