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

Breadcrumb

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

function DisallowDirectMagicInvokeCallSniff::process

* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

Parameters

int $stringPointer:

Overrides Sniff::process

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/PHP/DisallowDirectMagicInvokeCallSniff.php, line 33

Class

DisallowDirectMagicInvokeCallSniff

Namespace

SlevomatCodingStandard\Sniffs\PHP

Code

public function process(File $phpcsFile, $stringPointer) : void {
    $tokens = $phpcsFile->getTokens();
    $parenthesisOpenerPointer = TokenHelper::findNextEffective($phpcsFile, $stringPointer + 1);
    if ($tokens[$parenthesisOpenerPointer]['code'] !== T_OPEN_PARENTHESIS) {
        return;
    }
    if (strtolower($tokens[$stringPointer]['content']) !== '__invoke') {
        return;
    }
    $objectOperator = TokenHelper::findPreviousEffective($phpcsFile, $stringPointer - 1);
    if ($tokens[$objectOperator]['code'] !== T_OBJECT_OPERATOR) {
        return;
    }
    $fix = $phpcsFile->addFixableError('Direct call of __invoke() is disallowed.', $stringPointer, self::CODE_DISALLOWED_DIRECT_MAGIC_INVOKE_CALL);
    if (!$fix) {
        return;
    }
    $phpcsFile->fixer
        ->beginChangeset();
    FixerHelper::removeBetweenIncluding($phpcsFile, $objectOperator, $parenthesisOpenerPointer - 1);
    $phpcsFile->fixer
        ->endChangeset();
}
RSS feed
Powered by Drupal