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

Breadcrumb

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

function UseStatementHelper::getFileUseStatements

*

Return value

array<int, array<string, UseStatement>>

5 calls to UseStatementHelper::getFileUseStatements()
AlphabeticallySortedUsesSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Namespaces/AlphabeticallySortedUsesSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
UnusedUsesSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Namespaces/UnusedUsesSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
UselessAliasSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Namespaces/UselessAliasSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
UseSpacingSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Namespaces/UseSpacingSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
UseStatementHelper::getUseStatementsForPointer in vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php
*

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php, line 159

Class

UseStatementHelper
@internal

Namespace

SlevomatCodingStandard\Helpers

Code

public static function getFileUseStatements(File $phpcsFile) : array {
    $lazyValue = static function () use ($phpcsFile) : array {
        $useStatements = [];
        $tokens = $phpcsFile->getTokens();
        $namespaceAndOpenTagPointers = TokenHelper::findNextAll($phpcsFile, [
            T_OPEN_TAG,
            T_NAMESPACE,
        ], 0);
        $openTagPointer = $namespaceAndOpenTagPointers[0];
        foreach (self::getUseStatementPointers($phpcsFile, $openTagPointer) as $usePointer) {
            $pointerBeforeUseStatements = $openTagPointer;
            if (count($namespaceAndOpenTagPointers) > 1) {
                foreach (array_reverse($namespaceAndOpenTagPointers) as $namespaceAndOpenTagPointer) {
                    if ($namespaceAndOpenTagPointer < $usePointer) {
                        $pointerBeforeUseStatements = $namespaceAndOpenTagPointer;
                        break;
                    }
                }
            }
            $nextTokenFromUsePointer = TokenHelper::findNextEffective($phpcsFile, $usePointer + 1);
            $type = UseStatement::TYPE_CLASS;
            if ($tokens[$nextTokenFromUsePointer]['code'] === T_STRING) {
                if ($tokens[$nextTokenFromUsePointer]['content'] === 'const') {
                    $type = UseStatement::TYPE_CONSTANT;
                }
                elseif ($tokens[$nextTokenFromUsePointer]['content'] === 'function') {
                    $type = UseStatement::TYPE_FUNCTION;
                }
            }
            $name = self::getNameAsReferencedInClassFromUse($phpcsFile, $usePointer);
            $useStatement = new UseStatement($name, self::getFullyQualifiedTypeNameFromUse($phpcsFile, $usePointer), $usePointer, $type, self::getAlias($phpcsFile, $usePointer));
            $useStatements[$pointerBeforeUseStatements][UseStatement::getUniqueId($type, $name)] = $useStatement;
        }
        return $useStatements;
    };
    return SniffLocalCache::getAndSetIfNotCached($phpcsFile, 'useStatements', $lazyValue);
}

API Navigation

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