Skip to content

Commit c2ee356

Browse files
committed
Squiz/EmbeddedPhp: efficiency fix - bow out early if there is nothing to do
No need to go through the rest of the logic for the multi-line PHP block handling if there is nothing to do for the sniff.
1 parent 36e1a8c commit c2ee356

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ private function validateMultilineEmbeddedPhp($phpcsFile, $stackPtr, $closingTag
7979
}
8080

8181
$firstContent = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
82+
if ($firstContent === false) {
83+
// Unclosed PHP open tag at the end of a file. Nothing to do.
84+
return;
85+
}
8286

8387
if ($closingTag !== false) {
8488
$firstContentAfterBlock = $phpcsFile->findNext(T_WHITESPACE, ($closingTag + 1), $phpcsFile->numTokens, true);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
// This test case file MUST always start with a long open PHP tag set (with this comment) to prevent
3+
// the tests running into the "first PHP open tag excepted" condition breaking the tests.
4+
// Tests related to that "first PHP open tag excepted" condition should go in separate files.
5+
?>
6+
<!--
7+
The below test safeguards that if there is just an unclosed PHP open tag at the end of a file,
8+
the sniff bows out as there is nothing to do, even when there are multiple new lines after the open tag.
9+
-->
10+
<?php
11+
12+
13+
14+
15+
16+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
// This test case file MUST always start with a long open PHP tag set (with this comment) to prevent
3+
// the tests running into the "first PHP open tag excepted" condition breaking the tests.
4+
// Tests related to that "first PHP open tag excepted" condition should go in separate files.
5+
?>
6+
<!--
7+
The below test safeguards that if there is just an unclosed PHP open tag at the end of a file,
8+
the sniff bows out as there is nothing to do, even when there are multiple new lines after the open tag.
9+
-->
10+
<?=
11+
12+
13+
14+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
// This test case file MUST always start with a long open PHP tag set (with this comment) to prevent
3+
// the tests running into the "first PHP open tag excepted" condition breaking the tests.
4+
// Tests related to that "first PHP open tag excepted" condition should go in separate files.
5+
?>
6+
<!--
7+
The below test safeguards that if there is just an unclosed PHP open tag at the end of a file,
8+
the sniff bows out as there is nothing to do.
9+
-->
10+
<?php
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
// This test case file MUST always start with a long open PHP tag set (with this comment) to prevent
3+
// the tests running into the "first PHP open tag excepted" condition breaking the tests.
4+
// Tests related to that "first PHP open tag excepted" condition should go in separate files.
5+
?>
6+
<!--
7+
The below test safeguards that if there is just an unclosed PHP open tag at the end of a file,
8+
the sniff bows out as there is nothing to do.
9+
-->
10+
<?=

0 commit comments

Comments
 (0)