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

Breadcrumb

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

function UseStatementHelper::getUseStatementPointers

* Searches for all use statements in a file, skips bodies of classes and traits. * *

Return value

list<int>

2 calls to UseStatementHelper::getUseStatementPointers()
UseStatementHelper::getFileUseStatements in vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php
*
UseStatementHelper::getUseStatementPointer in vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/UseStatementHelper.php

File

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

Class

UseStatementHelper
@internal

Namespace

SlevomatCodingStandard\Helpers

Code

private static function getUseStatementPointers(File $phpcsFile, int $openTagPointer) : array {
    $lazy = static function () use ($phpcsFile, $openTagPointer) : array {
        $tokens = $phpcsFile->getTokens();
        $pointer = $openTagPointer + 1;
        $pointers = [];
        while (true) {
            $typesToFind = array_merge([
                T_USE,
            ], TokenHelper::$typeKeywordTokenCodes);
            $pointer = TokenHelper::findNext($phpcsFile, $typesToFind, $pointer);
            if ($pointer === null) {
                break;
            }
            $token = $tokens[$pointer];
            if (in_array($token['code'], TokenHelper::$typeKeywordTokenCodes, true)) {
                $pointer = $token['scope_closer'] + 1;
                continue;
            }
            if (self::isGroupUse($phpcsFile, $pointer)) {
                $pointer++;
                continue;
            }
            if (!self::isImportUse($phpcsFile, $pointer)) {
                $pointer++;
                continue;
            }
            $pointers[] = $pointer;
            $pointer++;
        }
        return $pointers;
    };
    return SniffLocalCache::getAndSetIfNotCached($phpcsFile, 'useStatementPointers', $lazy);
}

API Navigation

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