function AbstractFullyQualifiedGlobalReference::process
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
Parameters
int $openTagPointer:
Overrides Sniff::process
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Namespaces/ AbstractFullyQualifiedGlobalReference.php, line 62
Class
- AbstractFullyQualifiedGlobalReference
- @internal
Namespace
SlevomatCodingStandard\Sniffs\NamespacesCode
public function process(File $phpcsFile, $openTagPointer) : void {
if (TokenHelper::findPrevious($phpcsFile, T_OPEN_TAG, $openTagPointer - 1) !== null) {
return;
}
if (TokenHelper::findNext($phpcsFile, T_OPEN_USE_GROUP, $openTagPointer) !== null) {
return;
}
$tokens = $phpcsFile->getTokens();
$namespacePointers = NamespaceHelper::getAllNamespacesPointers($phpcsFile);
$referencedNames = ReferencedNameHelper::getAllReferencedNames($phpcsFile, $openTagPointer);
$include = array_flip($this->getNormalizedInclude());
$exclude = array_flip($this->getNormalizedExclude());
foreach ($referencedNames as $referencedName) {
$name = $referencedName->getNameAsReferencedInFile();
$namePointer = $referencedName->getStartPointer();
if (!$this->isValidType($referencedName)) {
continue;
}
if (NamespaceHelper::isFullyQualifiedName($name)) {
continue;
}
if (NamespaceHelper::hasNamespace($name)) {
continue;
}
if ($namespacePointers === []) {
continue;
}
$canonicalName = $this->isCaseSensitive() ? $name : strtolower($name);
$useStatements = UseStatementHelper::getUseStatementsForPointer($phpcsFile, $namePointer);
if (array_key_exists(UseStatement::getUniqueId($referencedName->getType(), $canonicalName), $useStatements)) {
$fullyQualifiedName = NamespaceHelper::resolveName($phpcsFile, $name, $referencedName->getType(), $namePointer);
if (NamespaceHelper::hasNamespace($fullyQualifiedName)) {
continue;
}
}
if ($include !== [] && !array_key_exists($canonicalName, $include)) {
continue;
}
if (array_key_exists($canonicalName, $exclude)) {
continue;
}
$fix = $phpcsFile->addFixableError(sprintf($this->getNotFullyQualifiedMessage(), $tokens[$namePointer]['content']), $namePointer, self::CODE_NON_FULLY_QUALIFIED);
if (!$fix) {
continue;
}
$phpcsFile->fixer
->beginChangeset();
$phpcsFile->fixer
->addContentBefore($namePointer, NamespaceHelper::NAMESPACE_SEPARATOR);
$phpcsFile->fixer
->endChangeset();
}
}