Skip to content

Commit f2b6798

Browse files
committed
Fixed bug #2664 : PSR12.Files.OpenTag incorrectly identifies PHP file with only an opening tag
1 parent ae3aae4 commit f2b6798

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
3535
- Fixed bug #2654 : Incorrect indentation for arguments of multiline function calls
3636
- Fixed bug #2656 : Squiz.WhiteSpace.MemberVarSpacing removes comments before first member var during auto fixing
3737
-- Thanks to Juliette Reinders Folmer for the patch
38+
- Fixed bug #2664 : PSR12.Files.OpenTag incorrectly identifies PHP file with only an opening tag
3839
</notes>
3940
<contents>
4041
<dir name="/">
@@ -1074,6 +1075,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
10741075
<file baseinstalldir="PHP/CodeSniffer" name="OpenTagUnitTest.2.inc.fixed" role="test" />
10751076
<file baseinstalldir="PHP/CodeSniffer" name="OpenTagUnitTest.3.inc" role="test" />
10761077
<file baseinstalldir="PHP/CodeSniffer" name="OpenTagUnitTest.4.inc" role="test" />
1078+
<file baseinstalldir="PHP/CodeSniffer" name="OpenTagUnitTest.5.inc" role="test" />
10771079
<file baseinstalldir="PHP/CodeSniffer" name="OpenTagUnitTest.php" role="test" />
10781080
</dir>
10791081
<dir name="Functions">

src/Standards/PSR12/Sniffs/Files/OpenTagSniff.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ public function process(File $phpcsFile, $stackPtr)
5252

5353
$tokens = $phpcsFile->getTokens();
5454
$next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
55+
if ($next === false) {
56+
// Empty file.
57+
return;
58+
}
59+
5560
if ($tokens[$next]['line'] === $tokens[$stackPtr]['line']) {
5661
$error = 'Opening PHP tag must be on a line by itself';
5762
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'NotAlone');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php

0 commit comments

Comments
 (0)