Skip to content

Commit a957a73

Browse files
committed
Fixed bug #2888 : PSR12.Files.FileHeader blank line error with multiple namespaces in one file
1 parent 26b1157 commit a957a73

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
3434
-- Thanks to Michał Bundyra for the patch
3535
- Fixed bug #2877 : PEAR.Functions.FunctionCallSignature false positive for array of functions
3636
-- Thanks to Vincent Langlet for the patch
37+
- Fixed bug #2888 : PSR12.Files.FileHeader blank line error with multiple namespaces in one file
3738
- Fixed bug #2926 : phpcs hangs when using arrow functions that return heredoc
3839
- Fixed bug #2943 : Redundant semicolon added to a file when fixing PSR2.Files.ClosingTag.NotAllowed
3940
- Fixed bug #2977 : File::isReference() does not detect return by reference for closures
@@ -1106,6 +1107,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
11061107
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.13.inc" role="test" />
11071108
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.14.inc" role="test" />
11081109
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.15.inc" role="test" />
1110+
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.16.inc" role="test" />
11091111
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.php" role="test" />
11101112
<file baseinstalldir="PHP/CodeSniffer" name="ImportStatementUnitTest.inc" role="test" />
11111113
<file baseinstalldir="PHP/CodeSniffer" name="ImportStatementUnitTest.inc.fixed" role="test" />

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ public function getHeaderLines(File $phpcsFile, $stackPtr)
197197
break;
198198
case T_DECLARE:
199199
case T_NAMESPACE:
200+
if (isset($tokens[$next]['scope_opener']) === true) {
201+
// If this statement is using bracketed syntax, it doesn't
202+
// apply to the entire files and so is not part of header.
203+
// The header has now ended and the main code block begins.
204+
break(2);
205+
}
206+
200207
$end = $phpcsFile->findEndOfStatement($next);
201208

202209
$headerLines[] = [
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Foo {
4+
5+
use Baz;
6+
7+
}
8+
9+
namespace Bar {
10+
11+
use Baz;
12+
13+
}

0 commit comments

Comments
 (0)