diff --git a/package.xml b/package.xml index 082d314a28..f75080f30b 100644 --- a/package.xml +++ b/package.xml @@ -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 @@ -1062,6 +1063,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + diff --git a/src/Standards/PSR12/Sniffs/Files/FileHeaderSniff.php b/src/Standards/PSR12/Sniffs/Files/FileHeaderSniff.php index 36bc443f28..1c6b0e4a6a 100644 --- a/src/Standards/PSR12/Sniffs/Files/FileHeaderSniff.php +++ b/src/Standards/PSR12/Sniffs/Files/FileHeaderSniff.php @@ -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; } @@ -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. diff --git a/src/Standards/PSR12/Tests/Files/FileHeaderUnitTest.10.inc b/src/Standards/PSR12/Tests/Files/FileHeaderUnitTest.10.inc new file mode 100644 index 0000000000..70c8a8afd3 --- /dev/null +++ b/src/Standards/PSR12/Tests/Files/FileHeaderUnitTest.10.inc @@ -0,0 +1,4 @@ +