class DisallowContinueWithoutIntegerOperandInSwitchSniff
Hierarchy
- class \SlevomatCodingStandard\Sniffs\ControlStructures\DisallowContinueWithoutIntegerOperandInSwitchSniff implements \PHP_CodeSniffer\Sniffs\Sniff
Expanded class hierarchy of DisallowContinueWithoutIntegerOperandInSwitchSniff
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ ControlStructures/ DisallowContinueWithoutIntegerOperandInSwitchSniff.php, line 14
Namespace
SlevomatCodingStandard\Sniffs\ControlStructuresView source
class DisallowContinueWithoutIntegerOperandInSwitchSniff implements Sniff {
public const CODE_DISALLOWED_CONTINUE_WITHOUT_INTEGER_OPERAND_IN_SWITCH = 'DisallowedContinueWithoutIntegerOperandInSwitch';
/**
* @return array<int, (int|string)>
*/
public function register() : array {
return [
T_CONTINUE,
];
}
/**
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
* @param int $continuePointer
*/
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();
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
DisallowContinueWithoutIntegerOperandInSwitchSniff::CODE_DISALLOWED_CONTINUE_WITHOUT_INTEGER_OPERAND_IN_SWITCH | public | constant | ||
DisallowContinueWithoutIntegerOperandInSwitchSniff::process | public | function | * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint * |
Overrides Sniff::process |
DisallowContinueWithoutIntegerOperandInSwitchSniff::register | public | function | * | Overrides Sniff::register |