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

Breadcrumb

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

function UseDeclarationSniff::shouldIgnoreUse

Check if this use statement is part of the namespace block.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:

int $stackPtr The position of the current token in: the stack passed in $tokens.

Return value

bool

1 call to UseDeclarationSniff::shouldIgnoreUse()
UseDeclarationSniff::process in vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Sniffs/Namespaces/UseDeclarationSniff.php
Processes this test, when one of its tokens is encountered.

File

vendor/squizlabs/php_codesniffer/src/Standards/PSR2/Sniffs/Namespaces/UseDeclarationSniff.php, line 277

Class

UseDeclarationSniff

Namespace

PHP_CodeSniffer\Standards\PSR2\Sniffs\Namespaces

Code

private function shouldIgnoreUse($phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    // Ignore USE keywords inside closures and during live coding.
    $next = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true);
    if ($next === false || $tokens[$next]['code'] === T_OPEN_PARENTHESIS) {
        return true;
    }
    // Ignore USE keywords for traits.
    if ($phpcsFile->hasCondition($stackPtr, [
        T_CLASS,
        T_TRAIT,
        T_ENUM,
    ]) === true) {
        return true;
    }
    return false;
}

API Navigation

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