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

Breadcrumb

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

function DisallowContinueWithoutIntegerOperandInSwitchSniff::process

* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

Parameters

int $continuePointer:

Overrides Sniff::process

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/ControlStructures/DisallowContinueWithoutIntegerOperandInSwitchSniff.php, line 33

Class

DisallowContinueWithoutIntegerOperandInSwitchSniff

Namespace

SlevomatCodingStandard\Sniffs\ControlStructures

Code

public function process(File $phpcsFile, $continuePointer) : void {
    $tokens = $phpcsFile->getTokens();
    $operandPointer = TokenHelper::findNextEffective($phpcsFile, $continuePointer + 1);
    if ($tokens[$operandPointer]['code'] === T_LNUMBER) {
        return;
    }
    $conditionTokenCode = current(array_reverse($tokens[$continuePointer]['conditions']));
    if ($conditionTokenCode !== T_SWITCH) {
        return;
    }
    $fix = $phpcsFile->addFixableError('Usage of "continue" without integer operand in "switch" is disallowed, use "break" instead.', $continuePointer, self::CODE_DISALLOWED_CONTINUE_WITHOUT_INTEGER_OPERAND_IN_SWITCH);
    if (!$fix) {
        return;
    }
    $phpcsFile->fixer
        ->beginChangeset();
    $phpcsFile->fixer
        ->replaceToken($continuePointer, 'break');
    $phpcsFile->fixer
        ->endChangeset();
}
RSS feed
Powered by Drupal