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

Breadcrumb

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

function DisallowIncrementAndDecrementOperatorsSniff::process

* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

Parameters

int $operatorPointer:

Overrides Sniff::process

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Operators/DisallowIncrementAndDecrementOperatorsSniff.php, line 35

Class

DisallowIncrementAndDecrementOperatorsSniff

Namespace

SlevomatCodingStandard\Sniffs\Operators

Code

public function process(File $phpcsFile, $operatorPointer) : void {
    $tokens = $phpcsFile->getTokens();
    
    /** @var int $nextPointer */
    $nextPointer = TokenHelper::findNextEffective($phpcsFile, $operatorPointer + 1);
    $afterVariableEndPointer = IdentificatorHelper::findEndPointer($phpcsFile, $nextPointer);
    $isPostOperator = $afterVariableEndPointer === null;
    if ($tokens[$operatorPointer]['code'] === T_INC) {
        if ($isPostOperator) {
            $code = self::CODE_DISALLOWED_POST_INCREMENT_OPERATOR;
            $message = 'Use of post-increment operator is disallowed.';
        }
        else {
            $code = self::CODE_DISALLOWED_PRE_INCREMENT_OPERATOR;
            $message = 'Use of pre-increment operator is disallowed.';
        }
    }
    else {
        if ($isPostOperator) {
            $code = self::CODE_DISALLOWED_POST_DECREMENT_OPERATOR;
            $message = 'Use of post-decrement operator is disallowed.';
        }
        else {
            $code = self::CODE_DISALLOWED_PRE_DECREMENT_OPERATOR;
            $message = 'Use of pre-decrement operator is disallowed.';
        }
    }
    $phpcsFile->addError($message, $operatorPointer, $code);
}
RSS feed
Powered by Drupal