Skip to content

Commit 234688d

Browse files
committed
Fixed bug #2608 : PSR2 throws errors for use statements when multiple namespaces are defined in a file
1 parent 15d4014 commit 234688d

File tree

3 files changed

+3
-8
lines changed

3 files changed

+3
-8
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
181181
-- Thanks to Juliette Reinders Folmer for the patch
182182
- Fixed bug #2575 : Custom error messages don't have data replaced when cache is enabled
183183
- Fixed bug #2601 : Squiz.WhiteSpace.FunctionSpacing incorrect fix when spacing is 0
184+
- Fixed bug #2608 : PSR2 throws errors for use statements when multiple namespaces are defined in a file
184185
</notes>
185186
<contents>
186187
<dir name="/">

src/Standards/PSR2/Sniffs/Namespaces/UseDeclarationSniff.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,7 @@ public function process(File $phpcsFile, $stackPtr)
167167

168168
// Make sure this USE comes after the first namespace declaration.
169169
$prev = $phpcsFile->findPrevious(T_NAMESPACE, ($stackPtr - 1));
170-
if ($prev !== false) {
171-
$first = $phpcsFile->findNext(T_NAMESPACE, 1);
172-
if ($prev !== $first) {
173-
$error = 'USE declarations must go after the first namespace declaration';
174-
$phpcsFile->addError($error, $stackPtr, 'UseAfterNamespace');
175-
}
176-
} else {
170+
if ($prev === false) {
177171
$next = $phpcsFile->findNext(T_NAMESPACE, ($stackPtr + 1));
178172
if ($next !== false) {
179173
$error = 'USE declarations must go after the namespace declaration';

src/Standards/PSR2/Tests/Namespaces/UseDeclarationUnitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function getErrorList($testFile='')
3434
5 => 1,
3535
6 => 1,
3636
7 => 1,
37-
12 => 2,
37+
12 => 1,
3838
];
3939
case 'UseDeclarationUnitTest.3.inc':
4040
return [

0 commit comments

Comments
 (0)