function UselessParenthesesSniff::checkParenthesesAroundString
1 call to UselessParenthesesSniff::checkParenthesesAroundString()
- 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 420
Class
Namespace
SlevomatCodingStandard\Sniffs\PHPCode
private function checkParenthesesAroundString(File $phpcsFile, int $parenthesisOpenerPointer) : void {
$tokens = $phpcsFile->getTokens();
/** @var int $stringPointer */
$stringPointer = TokenHelper::findNextEffective($phpcsFile, $parenthesisOpenerPointer + 1);
if ($tokens[$stringPointer]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
return;
}
$pointerAfterString = TokenHelper::findNextEffective($phpcsFile, $stringPointer + 1);
if ($pointerAfterString !== $tokens[$parenthesisOpenerPointer]['parenthesis_closer']) {
return;
}
$fix = $phpcsFile->addFixableError('Useless parentheses.', $parenthesisOpenerPointer, self::CODE_USELESS_PARENTHESES);
if (!$fix) {
return;
}
$phpcsFile->fixer
->beginChangeset();
FixerHelper::removeBetweenIncluding($phpcsFile, $parenthesisOpenerPointer, $stringPointer - 1);
FixerHelper::removeBetweenIncluding($phpcsFile, $stringPointer + 1, $tokens[$parenthesisOpenerPointer]['parenthesis_closer']);
$phpcsFile->fixer
->endChangeset();
}