Skip to content

Commit e33f41f

Browse files
committed
Squiz.PHP.EmbeddedPhp: prevent removing embedded PHP when no space between comment and close tag
When there is no space between a `/* .. */` comment and the close tag, PHPCS would report an `Empty embedded PHP tag found (Squiz.PHP.EmbeddedPhp.Empty)` error and the fixer would accidentally remove a complete line of embedded PHP. Includes unit tests.
1 parent 4162ad4 commit e33f41f

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ private function validateInlineEmbeddedPhp($phpcsFile, $stackPtr)
308308
}
309309

310310
// Check that there is one, and only one space at the start of the statement.
311-
$firstContent = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), ($closeTag - 1), true);
311+
$firstContent = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), $closeTag, true);
312312

313313
if ($firstContent === false) {
314314
$error = 'Empty embedded PHP tag found';

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,5 @@ function foo()
113113
<?php echo 'oops'; // Something.?>
114114

115115
<?php /* translators: My sites label */ ?>
116+
<?php /* translators: My sites label */?>
117+
<?php /* translators: My sites label */ ?>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,5 @@ function foo()
113113
<?php echo 'oops'; // Something. ?>
114114

115115
<?php /* translators: My sites label */ ?>
116+
<?php /* translators: My sites label */ ?>
117+
<?php /* translators: My sites label */ ?>

src/Standards/Squiz/Tests/PHP/EmbeddedPhpUnitTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public function getErrorList()
5353
102 => 1,
5454
112 => 1,
5555
113 => 1,
56+
116 => 1,
57+
117 => 1,
5658
);
5759

5860
}//end getErrorList()

0 commit comments

Comments
 (0)