function UselessParenthesesSniff::checkParenthesesAroundCaseInSwitch
1 call to UselessParenthesesSniff::checkParenthesesAroundCaseInSwitch()
- UselessParenthesesSniff::process in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ PHP/ UselessParenthesesSniff.php - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ PHP/ UselessParenthesesSniff.php, line 286
Class
Namespace
SlevomatCodingStandard\Sniffs\PHPCode
private function checkParenthesesAroundCaseInSwitch(File $phpcsFile, int $parenthesisOpenerPointer) : void {
$tokens = $phpcsFile->getTokens();
$pointerBeforeParenthesisOpener = TokenHelper::findPreviousEffective($phpcsFile, $parenthesisOpenerPointer - 1);
if ($tokens[$pointerBeforeParenthesisOpener]['code'] !== T_CASE) {
return;
}
$pointerAfterParenthesisCloser = TokenHelper::findNextEffective($phpcsFile, $tokens[$parenthesisOpenerPointer]['parenthesis_closer'] + 1);
if ($tokens[$pointerAfterParenthesisCloser]['code'] !== T_COLON) {
return;
}
$fix = $phpcsFile->addFixableError('Useless parentheses.', $parenthesisOpenerPointer, self::CODE_USELESS_PARENTHESES);
if (!$fix) {
return;
}
$contentStartPointer = TokenHelper::findNextEffective($phpcsFile, $parenthesisOpenerPointer + 1);
$contentEndPointer = TokenHelper::findPreviousEffective($phpcsFile, $tokens[$parenthesisOpenerPointer]['parenthesis_closer'] - 1);
$phpcsFile->fixer
->beginChangeset();
FixerHelper::removeBetweenIncluding($phpcsFile, $parenthesisOpenerPointer, $contentStartPointer - 1);
FixerHelper::removeBetweenIncluding($phpcsFile, $contentEndPointer + 1, $tokens[$parenthesisOpenerPointer]['parenthesis_closer']);
$phpcsFile->fixer
->endChangeset();
}