SlevomatCodingStandard\Helpers\ReferencedNameHelper::getAllReferencedNames PHP Method

getAllReferencedNames() public static method

public static getAllReferencedNames ( PHP_CodeSniffer_File $phpcsFile, integer $openTagPointer ) : ReferencedName[]
$phpcsFile PHP_CodeSniffer_File
$openTagPointer integer
return ReferencedName[] referenced names
    public static function getAllReferencedNames(PHP_CodeSniffer_File $phpcsFile, $openTagPointer)
    {
        $cacheKey = $phpcsFile->getFilename() . '-' . $openTagPointer;
        if (!isset(self::$allReferencedTypesCache[$cacheKey])) {
            self::$allReferencedTypesCache[$cacheKey] = self::createAllReferencedNames($phpcsFile, $openTagPointer);
        }
        return self::$allReferencedTypesCache[$cacheKey];
    }

Usage Example

コード例 #1
0
 /**
  * @param \PHP_CodeSniffer_File $phpcsFile
  * @param integer $openTagPointer
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $openTagPointer)
 {
     $referencedNames = ReferencedNameHelper::getAllReferencedNames($phpcsFile, $openTagPointer);
     $useStatements = UseStatementHelper::getUseStatements($phpcsFile, $openTagPointer);
     foreach ($referencedNames as $referencedName) {
         $pointer = $referencedName->getPointer();
         $name = $referencedName->getNameAsReferencedInFile();
         $normalizedName = UseStatement::normalizedNameAsReferencedInFile($name);
         if (isset($useStatements[$normalizedName]) && $referencedName->hasSameUseStatementType($useStatements[$normalizedName])) {
             $useStatement = $useStatements[$normalizedName];
             if (in_array($useStatement->getFullyQualifiedTypeName(), $this->getIgnoredNames(), true) || !StringHelper::endsWith($useStatement->getFullyQualifiedTypeName(), 'Exception') && $useStatement->getFullyQualifiedTypeName() !== 'Throwable' && (!StringHelper::endsWith($useStatement->getFullyQualifiedTypeName(), 'Error') || NamespaceHelper::hasNamespace($useStatement->getFullyQualifiedTypeName())) && !in_array($useStatement->getFullyQualifiedTypeName(), $this->getSpecialExceptionNames(), true)) {
                 continue;
             }
         } else {
             $fileNamespace = NamespaceHelper::findCurrentNamespaceName($phpcsFile, $pointer);
             $canonicalName = $name;
             if (!NamespaceHelper::isFullyQualifiedName($name) && $fileNamespace !== null) {
                 $canonicalName = sprintf('%s%s%s', $fileNamespace, NamespaceHelper::NAMESPACE_SEPARATOR, $name);
             }
             if (in_array($canonicalName, $this->getIgnoredNames(), true) || !StringHelper::endsWith($name, 'Exception') && $name !== 'Throwable' && (!StringHelper::endsWith($canonicalName, 'Error') || NamespaceHelper::hasNamespace($canonicalName)) && !in_array($canonicalName, $this->getSpecialExceptionNames(), true)) {
                 continue;
             }
         }
         if (!NamespaceHelper::isFullyQualifiedName($name)) {
             $phpcsFile->addError(sprintf('Exception %s should be referenced via a fully qualified name', $name), $pointer, self::CODE_NON_FULLY_QUALIFIED_EXCEPTION);
         }
     }
 }
All Usage Examples Of SlevomatCodingStandard\Helpers\ReferencedNameHelper::getAllReferencedNames