Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. NamespaceHelper.php

function NamespaceHelper::resolveName

4 calls to NamespaceHelper::resolveName()
AbstractFullyQualifiedGlobalReference::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Namespaces/AbstractFullyQualifiedGlobalReference.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
FullyQualifiedClassNameInAnnotationSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Namespaces/FullyQualifiedClassNameInAnnotationSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
NamespaceHelper::resolveClassName in vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/NamespaceHelper.php
ReferenceUsedNamesOnlySniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Namespaces/ReferenceUsedNamesOnlySniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/NamespaceHelper.php, line 162

Class

NamespaceHelper
Terms "unqualified", "qualified" and "fully qualified" have the same meaning as described here: http://php.net/manual/en/language.namespaces.rules.php

Namespace

SlevomatCodingStandard\Helpers

Code

public static function resolveName(File $phpcsFile, string $nameAsReferencedInFile, string $type, int $currentPointer) : string {
    if (self::isFullyQualifiedName($nameAsReferencedInFile)) {
        return $nameAsReferencedInFile;
    }
    $useStatements = UseStatementHelper::getUseStatementsForPointer($phpcsFile, $currentPointer);
    $uniqueId = UseStatement::getUniqueId($type, self::normalizeToCanonicalName($nameAsReferencedInFile));
    if (isset($useStatements[$uniqueId])) {
        return sprintf('%s%s', self::NAMESPACE_SEPARATOR, $useStatements[$uniqueId]->getFullyQualifiedTypeName());
    }
    $nameParts = self::getNameParts($nameAsReferencedInFile);
    $firstPartUniqueId = UseStatement::getUniqueId($type, $nameParts[0]);
    if (count($nameParts) > 1 && isset($useStatements[$firstPartUniqueId])) {
        return sprintf('%s%s%s%s', self::NAMESPACE_SEPARATOR, $useStatements[$firstPartUniqueId]->getFullyQualifiedTypeName(), self::NAMESPACE_SEPARATOR, implode(self::NAMESPACE_SEPARATOR, array_slice($nameParts, 1)));
    }
    $name = sprintf('%s%s', self::NAMESPACE_SEPARATOR, $nameAsReferencedInFile);
    if ($type === ReferencedName::TYPE_CONSTANT && defined($name)) {
        return $name;
    }
    $namespaceName = self::findCurrentNamespaceName($phpcsFile, $currentPointer);
    if ($namespaceName !== null) {
        $name = sprintf('%s%s%s', self::NAMESPACE_SEPARATOR, $namespaceName, $name);
    }
    return $name;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal