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

Breadcrumb

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

function UseStatementHelper::isImportUse

7 calls to UseStatementHelper::isImportUse()
LineLengthSniff::checkLineLength in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Files/LineLengthSniff.php
MultipleUsesPerLineSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Namespaces/MultipleUsesPerLineSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
UseDoesNotStartWithBackslashSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Namespaces/UseDoesNotStartWithBackslashSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
UseFromSameNamespaceSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Namespaces/UseFromSameNamespaceSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
UseOnlyWhitelistedNamespacesSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Namespaces/UseOnlyWhitelistedNamespacesSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

... See full list

File

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

Class

UseStatementHelper
@internal

Namespace

SlevomatCodingStandard\Helpers

Code

public static function isImportUse(File $phpcsFile, int $usePointer) : bool {
    $tokens = $phpcsFile->getTokens();
    $nextPointer = TokenHelper::findNextEffective($phpcsFile, $usePointer + 1);
    // Anonymous function use
    if ($tokens[$nextPointer]['code'] === T_OPEN_PARENTHESIS) {
        return false;
    }
    if ($tokens[$nextPointer]['code'] === T_STRING && in_array(strtolower($tokens[$nextPointer]['content']), [
        'function',
        'const',
    ], true)) {
        return true;
    }
    $previousPointer = TokenHelper::findPrevious($phpcsFile, [
        T_OPEN_TAG,
        T_DECLARE,
        T_NAMESPACE,
        T_OPEN_CURLY_BRACKET,
        T_CLOSE_CURLY_BRACKET,
    ], $usePointer);
    if (in_array($tokens[$previousPointer]['code'], [
        T_OPEN_TAG,
        T_DECLARE,
        T_NAMESPACE,
    ], true)) {
        return true;
    }
    if (array_key_exists('scope_condition', $tokens[$previousPointer])) {
        $scopeConditionPointer = $tokens[$previousPointer]['scope_condition'];
        if ($tokens[$previousPointer]['code'] === T_OPEN_CURLY_BRACKET && in_array($tokens[$scopeConditionPointer]['code'], TokenHelper::$typeWithAnonymousClassKeywordTokenCodes, true)) {
            return false;
        }
        // Trait use after another trait use
        if ($tokens[$scopeConditionPointer]['code'] === T_USE) {
            return false;
        }
        // Trait use after method or import use after function
        if ($tokens[$scopeConditionPointer]['code'] === T_FUNCTION) {
            return ClassHelper::getClassPointer($phpcsFile, $usePointer) === null;
        }
    }
    return true;
}

API Navigation

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