Skip to content

Commit 0aa44e9

Browse files
committed
Fixed bug #2616 : PSR12.Files.FileHeader false positive when file only contains docblock
1 parent 16ce122 commit 0aa44e9

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
2727
<license uri="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt">BSD 3-Clause License</license>
2828
<notes>
2929
- Fixed bug #2615 : Constant visibility false positive on non-class constants
30+
- Fixed bug #2616 : PSR12.Files.FileHeader false positive when file only contains docblock
3031
- Fixed bug #2619 : PSR12.Files.FileHeader locks up when inline comment is the last content in a file
3132
- Fixed bug #2621 : PSR12.Classes.AnonClassDeclaration.CloseBraceSameLine false positive for anon class passed as function argument
3233
-- Thanks to Martins Sipenko for the patch
@@ -1060,6 +1061,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
10601061
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.5.inc" role="test" />
10611062
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.6.inc" role="test" />
10621063
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.7.inc" role="test" />
1064+
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.8.inc" role="test" />
10631065
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.php" role="test" />
10641066
<file baseinstalldir="PHP/CodeSniffer" name="ImportStatementUnitTest.inc" role="test" />
10651067
<file baseinstalldir="PHP/CodeSniffer" name="ImportStatementUnitTest.php" role="test" />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function process(File $phpcsFile, $stackPtr)
154154
// Make sure there is a single blank line after
155155
// this block.
156156
$next = $phpcsFile->findNext(T_WHITESPACE, ($line['end'] + 1), null, true);
157-
if ($tokens[$next]['line'] !== ($tokens[$line['end']]['line'] + 2)) {
157+
if ($next !== false && $tokens[$next]['line'] !== ($tokens[$line['end']]['line'] + 2)) {
158158
$error = 'Header blocks must be followed by a single blank line';
159159
$fix = $phpcsFile->addFixableError($error, $line['end'], 'SpacingAfterBlock');
160160
if ($fix === true) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
/**
4+
* Comment here.
5+
*/

0 commit comments

Comments
 (0)