Skip to content

Commit

Permalink
Fixed bug #2616 : PSR12.Files.FileHeader false positive when file onl…
Browse files Browse the repository at this point in the history
…y contains docblock
  • Loading branch information
gsherwood committed Oct 3, 2019
1 parent 16ce122 commit 0aa44e9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<license uri="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt">BSD 3-Clause License</license>
<notes>
- Fixed bug #2615 : Constant visibility false positive on non-class constants
- Fixed bug #2616 : PSR12.Files.FileHeader false positive when file only contains docblock
- Fixed bug #2619 : PSR12.Files.FileHeader locks up when inline comment is the last content in a file
- Fixed bug #2621 : PSR12.Classes.AnonClassDeclaration.CloseBraceSameLine false positive for anon class passed as function argument
-- Thanks to Martins Sipenko for the patch
Expand Down Expand Up @@ -1060,6 +1061,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.5.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.6.inc" role="test" />
<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.php" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="ImportStatementUnitTest.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="ImportStatementUnitTest.php" role="test" />
Expand Down
2 changes: 1 addition & 1 deletion src/Standards/PSR12/Sniffs/Files/FileHeaderSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function process(File $phpcsFile, $stackPtr)
// Make sure there is a single blank line after
// this block.
$next = $phpcsFile->findNext(T_WHITESPACE, ($line['end'] + 1), null, true);
if ($tokens[$next]['line'] !== ($tokens[$line['end']]['line'] + 2)) {
if ($next !== false && $tokens[$next]['line'] !== ($tokens[$line['end']]['line'] + 2)) {
$error = 'Header blocks must be followed by a single blank line';
$fix = $phpcsFile->addFixableError($error, $line['end'], 'SpacingAfterBlock');
if ($fix === true) {
Expand Down
5 changes: 5 additions & 0 deletions src/Standards/PSR12/Tests/Files/FileHeaderUnitTest.8.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

/**
* Comment here.
*/

0 comments on commit 0aa44e9

Please sign in to comment.