Skip to content

Commit 8b7c477

Browse files
authored
Merge pull request #838 from PHPCSStandards/feature/squiz-embeddedphp-another-fixer-conflict
Squiz/EmbeddedPhp: bug fix - prevent fixer conflict
2 parents 46fbb5d + 25f72e4 commit 8b7c477

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/Standards/Squiz/Sniffs/PHP/EmbeddedPhpSniff.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,9 @@ private function validateMultilineEmbeddedPhp($phpcsFile, $stackPtr, $closingTag
292292
}
293293

294294
// Check for a blank line at the bottom.
295-
if ((isset($tokens[$lastContent]['scope_closer']) === false
296-
|| $tokens[$lastContent]['scope_closer'] !== $lastContent)
295+
$lastNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($closingTag - 1), ($stackPtr + 1), true);
296+
if ((isset($tokens[$lastNonEmpty]['scope_closer']) === false
297+
|| $tokens[$lastNonEmpty]['scope_closer'] !== $lastNonEmpty)
297298
&& $tokens[$lastContent]['line'] < ($tokens[$closingTag]['line'] - 1)
298299
) {
299300
// Find a token on the blank line to throw the error on.

src/Standards/Squiz/Tests/PHP/EmbeddedPhpUnitTest.1.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,13 @@ echo $j;
283283
echo $j;
284284
?>
285285

286+
<?php
287+
enum BlankLineBeforeCloseShouldBeIgnoredWhenLastBeforeIsCloseCurlyForScope
288+
{
289+
}//trailing comment
290+
291+
?>
292+
286293
<?php
287294
// This test case file MUST always end with an unclosed long open PHP tag (with this comment) to prevent
288295
// the tests running into the "last PHP closing tag excepted" condition breaking tests.

src/Standards/Squiz/Tests/PHP/EmbeddedPhpUnitTest.1.inc.fixed

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,13 @@ echo $j;
301301
echo $j;
302302
?>
303303

304+
<?php
305+
enum BlankLineBeforeCloseShouldBeIgnoredWhenLastBeforeIsCloseCurlyForScope
306+
{
307+
}//trailing comment
308+
309+
?>
310+
304311
<?php
305312
// This test case file MUST always end with an unclosed long open PHP tag (with this comment) to prevent
306313
// the tests running into the "last PHP closing tag excepted" condition breaking tests.

0 commit comments

Comments
 (0)