Skip to content

Commit

Permalink
Fixed bug #2664 : PSR12.Files.OpenTag incorrectly identifies PHP file…
Browse files Browse the repository at this point in the history
… with only an opening tag
  • Loading branch information
gsherwood committed Oct 23, 2019
1 parent ae3aae4 commit f2b6798
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #2654 : Incorrect indentation for arguments of multiline function calls
- Fixed bug #2656 : Squiz.WhiteSpace.MemberVarSpacing removes comments before first member var during auto fixing
-- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #2664 : PSR12.Files.OpenTag incorrectly identifies PHP file with only an opening tag
</notes>
<contents>
<dir name="/">
Expand Down Expand Up @@ -1074,6 +1075,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<file baseinstalldir="PHP/CodeSniffer" name="OpenTagUnitTest.2.inc.fixed" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="OpenTagUnitTest.3.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="OpenTagUnitTest.4.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="OpenTagUnitTest.5.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="OpenTagUnitTest.php" role="test" />
</dir>
<dir name="Functions">
Expand Down
5 changes: 5 additions & 0 deletions src/Standards/PSR12/Sniffs/Files/OpenTagSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public function process(File $phpcsFile, $stackPtr)

$tokens = $phpcsFile->getTokens();
$next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
if ($next === false) {
// Empty file.
return;
}

if ($tokens[$next]['line'] === $tokens[$stackPtr]['line']) {
$error = 'Opening PHP tag must be on a line by itself';
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'NotAlone');
Expand Down
1 change: 1 addition & 0 deletions src/Standards/PSR12/Tests/Files/OpenTagUnitTest.5.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php

0 comments on commit f2b6798

Please sign in to comment.