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

Breadcrumb

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

function DisallowLateStaticBindingForConstantsSniff::process

* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

Parameters

int $staticPointer:

Overrides Sniff::process

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Classes/DisallowLateStaticBindingForConstantsSniff.php, line 33

Class

DisallowLateStaticBindingForConstantsSniff

Namespace

SlevomatCodingStandard\Sniffs\Classes

Code

public function process(File $phpcsFile, $staticPointer) : void {
    $tokens = $phpcsFile->getTokens();
    $doubleColonPointer = TokenHelper::findNextEffective($phpcsFile, $staticPointer + 1);
    if ($tokens[$doubleColonPointer]['code'] !== T_DOUBLE_COLON) {
        return;
    }
    $stringPointer = TokenHelper::findNextEffective($phpcsFile, $doubleColonPointer + 1);
    if ($tokens[$stringPointer]['code'] !== T_STRING) {
        return;
    }
    if (strtolower($tokens[$stringPointer]['content']) === 'class') {
        return;
    }
    $pointerAfterString = TokenHelper::findNextEffective($phpcsFile, $stringPointer + 1);
    if ($tokens[$pointerAfterString]['code'] === T_OPEN_PARENTHESIS) {
        return;
    }
    $fix = $phpcsFile->addFixableError('Late static binding for constants is disallowed.', $staticPointer, self::CODE_DISALLOWED_LATE_STATIC_BINDING_FOR_CONSTANT);
    if (!$fix) {
        return;
    }
    $phpcsFile->fixer
        ->beginChangeset();
    $phpcsFile->fixer
        ->replaceToken($staticPointer, 'self');
    $phpcsFile->fixer
        ->endChangeset();
}
RSS feed
Powered by Drupal