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

Breadcrumb

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

function CompoundNamespaceDepthSniff::process

Processes this test, when one of its tokens is encountered.

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

void

Overrides Sniff::process

File

vendor/squizlabs/php_codesniffer/src/Standards/PSR12/Sniffs/Namespaces/CompoundNamespaceDepthSniff.php, line 47

Class

CompoundNamespaceDepthSniff

Namespace

PHP_CodeSniffer\Standards\PSR12\Sniffs\Namespaces

Code

public function process(File $phpcsFile, $stackPtr) {
    $this->maxDepth = (int) $this->maxDepth;
    $tokens = $phpcsFile->getTokens();
    $end = $phpcsFile->findNext(T_CLOSE_USE_GROUP, $stackPtr + 1);
    if ($end === false) {
        return;
    }
    $depth = 1;
    for ($i = $stackPtr + 1; $i <= $end; $i++) {
        if ($tokens[$i]['code'] === T_NS_SEPARATOR) {
            $depth++;
            continue;
        }
        if ($i === $end || $tokens[$i]['code'] === T_COMMA) {
            // End of a namespace.
            if ($depth > $this->maxDepth) {
                $error = 'Compound namespaces cannot have a depth more than %s';
                $data = [
                    $this->maxDepth,
                ];
                $phpcsFile->addError($error, $i, 'TooDeep', $data);
            }
            $depth = 1;
        }
    }
}

API Navigation

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