-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
… use statements before the namespace declaration
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,6 +122,12 @@ public function process(File $phpcsFile, $stackPtr) | |
$error = 'USE declarations must go after the first namespace declaration'; | ||
$phpcsFile->addError($error, $stackPtr, 'UseAfterNamespace'); | ||
} | ||
} else { | ||
$next = $phpcsFile->findNext(T_NAMESPACE, ($stackPtr + 1)); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
gsherwood
Author
Member
|
||
if ($next !== false) { | ||
$error = 'USE declarations must go after the namespace declaration'; | ||
$phpcsFile->addError($error, $stackPtr, 'UseBeforeNamespace'); | ||
} | ||
} | ||
|
||
// Only interested in the last USE statement from here onwards. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
use BarClass as Bar; | ||
use My\Full\Classname as Another; | ||
use ArrayObject; | ||
|
||
namespace AnotherProject; | ||
|
||
$foo = 'bar'; | ||
|
Just a thought, but I don't think this check now allows for scoped namespaces with multiple namespaces in one file, which would result in false positives.