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

Breadcrumb

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

function ReferenceUsedNamesOnlySniff::getReferences

*

Return value

list<stdClass>

1 call to ReferenceUsedNamesOnlySniff::getReferences()
ReferenceUsedNamesOnlySniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Namespaces/ReferenceUsedNamesOnlySniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Namespaces/ReferenceUsedNamesOnlySniff.php, line 670

Class

ReferenceUsedNamesOnlySniff

Namespace

SlevomatCodingStandard\Sniffs\Namespaces

Code

private function getReferences(File $phpcsFile, int $openTagPointer) : array {
    $tokens = $phpcsFile->getTokens();
    $references = [];
    foreach (ReferencedNameHelper::getAllReferencedNames($phpcsFile, $openTagPointer) as $referencedName) {
        $reference = new stdClass();
        $reference->source = self::SOURCE_CODE;
        $reference->name = $referencedName->getNameAsReferencedInFile();
        $reference->type = $referencedName->getType();
        $reference->startPointer = $referencedName->getStartPointer();
        $reference->endPointer = $referencedName->getEndPointer();
        $reference->isClass = $referencedName->isClass();
        $reference->isConstant = $referencedName->isConstant();
        $reference->isFunction = $referencedName->isFunction();
        $references[] = $reference;
    }
    foreach (ReferencedNameHelper::getAllReferencedNamesInAttributes($phpcsFile, $openTagPointer) as $referencedName) {
        $reference = new stdClass();
        $reference->source = self::SOURCE_ATTRIBUTE;
        $reference->name = $referencedName->getNameAsReferencedInFile();
        $reference->type = $referencedName->getType();
        $reference->startPointer = $referencedName->getStartPointer();
        $reference->endPointer = $referencedName->getEndPointer();
        $reference->isClass = $referencedName->isClass();
        $reference->isConstant = $referencedName->isConstant();
        $reference->isFunction = $referencedName->isFunction();
        $references[] = $reference;
    }
    if (!$this->searchAnnotations) {
        return $references;
    }
    $searchAnnotationsPointer = $openTagPointer + 1;
    while (true) {
        $docCommentOpenPointer = TokenHelper::findNext($phpcsFile, T_DOC_COMMENT_OPEN_TAG, $searchAnnotationsPointer);
        if ($docCommentOpenPointer === null) {
            break;
        }
        $parsedDocComment = DocCommentHelper::parseDocComment($phpcsFile, $docCommentOpenPointer);
        if ($parsedDocComment !== null) {
            $annotations = AnnotationHelper::getAnnotations($phpcsFile, $docCommentOpenPointer);
            foreach ($annotations as $annotation) {
                
                /** @var list<IdentifierTypeNode> $identifierTypeNodes */
                $identifierTypeNodes = AnnotationHelper::getAnnotationNodesByType($annotation->getNode(), IdentifierTypeNode::class);
                foreach ($identifierTypeNodes as $typeHintNode) {
                    $typeHint = $typeHintNode->name;
                    $lowercasedTypeHint = strtolower($typeHint);
                    if (TypeHintHelper::isSimpleTypeHint($lowercasedTypeHint) || TypeHintHelper::isSimpleUnofficialTypeHints($lowercasedTypeHint) || !TypeHelper::isTypeName($typeHint)) {
                        continue;
                    }
                    $reference = new stdClass();
                    $reference->source = self::SOURCE_ANNOTATION;
                    $reference->parsedDocComment = $parsedDocComment;
                    $reference->annotation = $annotation;
                    $reference->nameNode = $typeHintNode;
                    $reference->name = $typeHint;
                    $reference->type = ReferencedName::TYPE_CLASS;
                    $reference->startPointer = $annotation->getStartPointer();
                    $reference->endPointer = null;
                    $reference->isClass = true;
                    $reference->isConstant = false;
                    $reference->isFunction = false;
                    $references[] = $reference;
                }
                
                /** @var list<ConstFetchNode> $constantFetchNodes */
                $constantFetchNodes = AnnotationHelper::getAnnotationNodesByType($annotation->getNode(), ConstFetchNode::class);
                foreach ($constantFetchNodes as $constantFetchNode) {
                    $reference = new stdClass();
                    $reference->source = self::SOURCE_ANNOTATION_CONSTANT_FETCH;
                    $reference->parsedDocComment = $parsedDocComment;
                    $reference->annotation = $annotation;
                    $reference->constantFetchNode = $constantFetchNode;
                    $reference->name = $constantFetchNode->className;
                    $reference->type = ReferencedName::TYPE_CLASS;
                    $reference->startPointer = $annotation->getStartPointer();
                    $reference->endPointer = null;
                    $reference->isClass = true;
                    $reference->isConstant = false;
                    $reference->isFunction = false;
                    $references[] = $reference;
                }
            }
        }
        $searchAnnotationsPointer = $tokens[$docCommentOpenPointer]['comment_closer'] + 1;
    }
    return $references;
}

API Navigation

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