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

Breadcrumb

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

function ForbiddenClassesSniff::process

* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

Parameters

int $tokenPointer:

Overrides Sniff::process

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/PHP/ForbiddenClassesSniff.php, line 90

Class

ForbiddenClassesSniff

Namespace

SlevomatCodingStandard\Sniffs\PHP

Code

public function process(File $phpcsFile, $tokenPointer) : void {
    $tokens = $phpcsFile->getTokens();
    $token = $tokens[$tokenPointer];
    $nameTokens = array_merge(TokenHelper::getNameTokenCodes(), TokenHelper::$ineffectiveTokenCodes);
    if ($token['code'] === T_IMPLEMENTS || $token['code'] === T_USE && UseStatementHelper::isTraitUse($phpcsFile, $tokenPointer)) {
        $endTokenPointer = TokenHelper::findNext($phpcsFile, [
            T_SEMICOLON,
            T_OPEN_CURLY_BRACKET,
        ], $tokenPointer);
        $references = $this->getAllReferences($phpcsFile, $tokenPointer, $endTokenPointer);
        if ($token['code'] === T_IMPLEMENTS) {
            $this->checkReferences($phpcsFile, $tokenPointer, $references, $this->forbiddenInterfaces);
        }
        else {
            // Fixer does not work when traits contains aliases
            $this->checkReferences($phpcsFile, $tokenPointer, $references, $this->forbiddenTraits, $tokens[$endTokenPointer]['code'] !== T_OPEN_CURLY_BRACKET);
        }
    }
    elseif (in_array($token['code'], [
        T_NEW,
        T_EXTENDS,
    ], true)) {
        $endTokenPointer = TokenHelper::findNextExcluding($phpcsFile, $nameTokens, $tokenPointer + 1);
        $references = $this->getAllReferences($phpcsFile, $tokenPointer, $endTokenPointer);
        $this->checkReferences($phpcsFile, $tokenPointer, $references, $token['code'] === T_NEW ? $this->forbiddenClasses : $this->forbiddenExtends);
    }
    elseif ($token['code'] === T_DOUBLE_COLON && !$this->isTraitsConflictResolutionToken($token)) {
        $startTokenPointer = TokenHelper::findPreviousExcluding($phpcsFile, $nameTokens, $tokenPointer - 1);
        $references = $this->getAllReferences($phpcsFile, $startTokenPointer, $tokenPointer);
        $this->checkReferences($phpcsFile, $tokenPointer, $references, $this->forbiddenClasses);
    }
}
RSS feed
Powered by Drupal