Skip to content

Commit

Permalink
Fixed bug #2676 : PSR12.Files.FileHeader locks up when file ends with…
Browse files Browse the repository at this point in the history
… multiple inline comments
  • Loading branch information
gsherwood committed Oct 30, 2019
1 parent a37d543 commit b1c7d88
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions package.xml
Expand Up @@ -31,6 +31,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #2638 : Squiz.CSS.DuplicateClassDefinitionSniff sees comments as part of the class name
-- Thanks to Raphael Horber for the patch
- Fixed bug #2674 : Squiz.Functions.FunctionDeclarationArgumentSpacing prints wrong argument name in error message
- Fixed bug #2676 : PSR12.Files.FileHeader locks up when file ends with multiple inline comments
</notes>
<contents>
<dir name="/">
Expand Down Expand Up @@ -1062,6 +1063,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.7.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.8.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.9.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.10.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.php" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="ImportStatementUnitTest.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="ImportStatementUnitTest.php" role="test" />
Expand Down
7 changes: 6 additions & 1 deletion src/Standards/PSR12/Sniffs/Files/FileHeaderSniff.php
Expand Up @@ -139,6 +139,11 @@ public function process(File $phpcsFile, $stackPtr)
// Skip comments as PSR-12 doesn't say if these are allowed or not.
if (isset(Tokens::$commentTokens[$tokens[$next]['code']]) === true) {
$next = $phpcsFile->findNext(Tokens::$commentTokens, ($next + 1), null, true);
if ($next === false) {
// We reached the end of the file.
break(2);
}

$next--;
break;
}
Expand All @@ -148,7 +153,7 @@ public function process(File $phpcsFile, $stackPtr)
}//end switch

$next = $phpcsFile->findNext(T_WHITESPACE, ($next + 1), null, true);
} while ($next !== false && ($next !== $phpcsFile->numTokens - 1));
} while ($next !== false);

if (count($headerLines) === 1) {
// This is only an open tag and doesn't contain the file header.
Expand Down
4 changes: 4 additions & 0 deletions src/Standards/PSR12/Tests/Files/FileHeaderUnitTest.10.inc
@@ -0,0 +1,4 @@
<?php
// Do nothing
// Do nothing
// Do nothing

0 comments on commit b1c7d88

Please sign in to comment.