Skip to content

Commit

Permalink
Ignore whitespace between tags in unreachable test
Browse files Browse the repository at this point in the history
  • Loading branch information
fredden committed Feb 27, 2023
1 parent ed8e00d commit fbff4a1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Standards/Squiz/Sniffs/PHP/NonExecutableCodeSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ public function process(File $phpcsFile, $stackPtr)
continue;
}

// Skip close PHP tag, followed by whitespace, followed by open PHP tag.
if ($tokens[$i]['code'] === T_INLINE_HTML && \trim($tokens[$i]['content']) === '') {
$i = $phpcsFile->findNext(T_OPEN_TAG, $i, $end);
continue;
}

$line = $tokens[$i]['line'];
if ($line > $lastLine) {
$type = substr($tokens[$stackPtr]['type'], 2);
Expand Down
15 changes: 15 additions & 0 deletions src/Standards/Squiz/Tests/PHP/NonExecutableCodeUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,21 @@ class TestAlternativeControlStructures {
}
}

// There should be no problem with the following code.
?>

<?php if (true): ?>
<?php foreach ([] as $item): ?>
<?php continue; ?>
<?php endforeach; ?>
<?php endif; ?>

<?php if (true) { ?>
<?php foreach ([] as $item) { ?>
<?php continue; ?>
<?php } ?>
<?php }

$var_after_class_in_global_space = 1;
do_something_else();

Expand Down

0 comments on commit fbff4a1

Please sign in to comment.