Skip to content
Snippets Groups Projects
Commit 4283dae8 authored by Klaus Purer's avatar Klaus Purer
Browse files

Allow use statement aliasing even in the own namespace of the class

parent a5b5f6b5
Branches
Tags
No related merge requests found
......@@ -76,7 +76,11 @@ class Drupal_Sniffs_Classes_UnusedUseStatementSniff implements PHP_CodeSniffer_S
// Check if the referenced class is in the same namespace as the current
// file. If it is then the use statement is not necessary.
$namespacePtr = $phpcsFile->findPrevious([T_NAMESPACE], $stackPtr);
if ($namespacePtr !== false) {
// Check if the use statement does aliasing with the "as" keyword. Aliasing
// is allowed even in the same namespace.
$aliasUsed = $phpcsFile->findPrevious(T_AS, ($classPtr - 1), $stackPtr);
if ($namespacePtr !== false && $aliasUsed === false) {
$nsEnd = $phpcsFile->findNext(
[
T_NS_SEPARATOR,
......
......@@ -15,6 +15,7 @@ use Another\UnusedUse;
use Example\MyUrlHelper;
use MyNamespace\Depth\UnusedSameNamespace;
use /* I like weird comment placements */ MyNamespace\Depth\AnotherUnusedSameNamespace /* Oh yes I do */;
use MyNamespace\Depth\SomeClass as CoreSomeClass;
/**
* Bla.
......@@ -51,4 +52,11 @@ class Pum {
}
/**
* Renamed class from same namespace.
*/
protected function test5(CoreSomeClass $x) {
}
}
......@@ -7,6 +7,7 @@ use Thing\Fail\ActuallyUsed;
use Test\TraitTest;
use Thing\DifferentName as UsedOtherName;
use Example\MyUrlHelper;
use MyNamespace\Depth\SomeClass as CoreSomeClass;
/**
* Bla.
......@@ -43,4 +44,11 @@ class Pum {
}
/**
* Renamed class from same namespace.
*/
protected function test5(CoreSomeClass $x) {
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment