Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions ImportDetection/SniffHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions ImportDetection/Symbol.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
Expand Down