Skip to content

Commit

Permalink
Fixed bug #2888 : PSR12.Files.FileHeader blank line error with multip…
Browse files Browse the repository at this point in the history
…le namespaces in one file
  • Loading branch information
gsherwood committed Jun 22, 2020
1 parent 26b1157 commit a957a73
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- Thanks to Michał Bundyra for the patch
- Fixed bug #2877 : PEAR.Functions.FunctionCallSignature false positive for array of functions
-- Thanks to Vincent Langlet for the patch
- Fixed bug #2888 : PSR12.Files.FileHeader blank line error with multiple namespaces in one file
- Fixed bug #2926 : phpcs hangs when using arrow functions that return heredoc
- Fixed bug #2943 : Redundant semicolon added to a file when fixing PSR2.Files.ClosingTag.NotAllowed
- Fixed bug #2977 : File::isReference() does not detect return by reference for closures
Expand Down Expand Up @@ -1106,6 +1107,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.13.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.14.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.15.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.16.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.inc.fixed" role="test" />
Expand Down
7 changes: 7 additions & 0 deletions src/Standards/PSR12/Sniffs/Files/FileHeaderSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ public function getHeaderLines(File $phpcsFile, $stackPtr)
break;
case T_DECLARE:
case T_NAMESPACE:
if (isset($tokens[$next]['scope_opener']) === true) {
// If this statement is using bracketed syntax, it doesn't
// apply to the entire files and so is not part of header.
// The header has now ended and the main code block begins.
break(2);
}

$end = $phpcsFile->findEndOfStatement($next);

$headerLines[] = [
Expand Down
13 changes: 13 additions & 0 deletions src/Standards/PSR12/Tests/Files/FileHeaderUnitTest.16.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Foo {

use Baz;

}

namespace Bar {

use Baz;

}

0 comments on commit a957a73

Please sign in to comment.