diff --git a/ImportDetection/SniffHelpers.php b/ImportDetection/SniffHelpers.php index 049d487..b4651f6 100644 --- a/ImportDetection/SniffHelpers.php +++ b/ImportDetection/SniffHelpers.php @@ -165,7 +165,7 @@ public function getImportedSymbolsFromImportStatement(File $phpcsFile, $stackPtr if (! $endOfImportPtr) { $endOfImportPtr = $endOfStatementPtr; } - $lastStringPtr = $phpcsFile->findPrevious([T_STRING], $endOfImportPtr - 1, $stackPtr); + $lastStringPtr = $phpcsFile->findPrevious([T_STRING, T_NAME_QUALIFIED], $endOfImportPtr - 1, $stackPtr); if (! $lastStringPtr || ! isset($tokens[$lastStringPtr])) { return []; } @@ -243,9 +243,15 @@ public function isTokenADefinition(array $token): bool { public function getFullSymbol($phpcsFile, $stackPtr): Symbol { $originalPtr = $stackPtr; $tokens = $phpcsFile->getTokens(); + + $currentToken = Symbol::getTokenWithPosition($tokens[$stackPtr], $stackPtr); + + if ($tokens[$stackPtr]['type'] === 'T_NAME_QUALIFIED') { + return new Symbol([$currentToken]); + } + // go backwards and forward and collect all the tokens until we encounter // anything other than a backslash or a string - $currentToken = Symbol::getTokenWithPosition($tokens[$stackPtr], $stackPtr); $fullSymbolParts = []; while ($this->isTokenASymbolPart($currentToken)) { $fullSymbolParts[] = $currentToken; diff --git a/ImportDetection/Symbol.php b/ImportDetection/Symbol.php index 142b5d2..a0d1a91 100644 --- a/ImportDetection/Symbol.php +++ b/ImportDetection/Symbol.php @@ -39,6 +39,10 @@ public function getAlias(): string { if ($this->alias) { return $this->alias->getName(); } + if (count($this->tokens) === 1 && $this->tokens[0]['type'] === 'T_NAME_QUALIFIED') { + $parts = explode('\\', $this->tokens[0]['content']); + return $parts[count($parts) - 1]; + } return $this->tokens[count($this->tokens) - 1]['content']; }