function UselessAliasSniff::process
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
Parameters
int $openTagPointer:
Overrides Sniff::process
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Namespaces/ UselessAliasSniff.php, line 36
Class
Namespace
SlevomatCodingStandard\Sniffs\NamespacesCode
public function process(File $phpcsFile, $openTagPointer) : void {
if (TokenHelper::findPrevious($phpcsFile, T_OPEN_TAG, $openTagPointer - 1) !== null) {
return;
}
$fileUseStatements = UseStatementHelper::getFileUseStatements($phpcsFile);
if (count($fileUseStatements) === 0) {
return;
}
foreach ($fileUseStatements as $useStatements) {
foreach ($useStatements as $useStatement) {
if ($useStatement->getAlias() === null) {
continue;
}
$unqualifiedName = NamespaceHelper::getUnqualifiedNameFromFullyQualifiedName($useStatement->getFullyQualifiedTypeName());
if ($unqualifiedName !== $useStatement->getAlias()) {
continue;
}
$fix = $phpcsFile->addFixableError(sprintf('Useless alias "%s" for use of "%s".', $useStatement->getAlias(), $useStatement->getFullyQualifiedTypeName()), $useStatement->getPointer(), self::CODE_USELESS_ALIAS);
if (!$fix) {
continue;
}
$asPointer = TokenHelper::findNext($phpcsFile, T_AS, $useStatement->getPointer() + 1);
$nameEndPointer = TokenHelper::findPrevious($phpcsFile, TokenHelper::getOnlyNameTokenCodes(), $asPointer - 1);
$useSemicolonPointer = TokenHelper::findNext($phpcsFile, T_SEMICOLON, $asPointer + 1);
$phpcsFile->fixer
->beginChangeset();
FixerHelper::removeBetween($phpcsFile, $nameEndPointer, $useSemicolonPointer);
$phpcsFile->fixer
->endChangeset();
}
}
}