function LanguageConstructWithParenthesesSniff::process
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
Parameters
int $languageConstructPointer:
Overrides Sniff::process
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ ControlStructures/ LanguageConstructWithParenthesesSniff.php, line 60
Class
Namespace
SlevomatCodingStandard\Sniffs\ControlStructuresCode
public function process(File $phpcsFile, $languageConstructPointer) : void {
$tokens = $phpcsFile->getTokens();
/** @var int $openParenthesisPointer */
$openParenthesisPointer = TokenHelper::findNextEffective($phpcsFile, $languageConstructPointer + 1);
if ($tokens[$openParenthesisPointer]['code'] !== T_OPEN_PARENTHESIS) {
return;
}
$closeParenthesisPointer = $tokens[$openParenthesisPointer]['parenthesis_closer'];
$afterCloseParenthesisPointer = TokenHelper::findNextEffective($phpcsFile, $closeParenthesisPointer + 1);
if (!in_array($tokens[$afterCloseParenthesisPointer]['code'], [
T_SEMICOLON,
T_CLOSE_PARENTHESIS,
T_CLOSE_SHORT_ARRAY,
], true)) {
return;
}
$containsContentBetweenParentheses = TokenHelper::findNextEffective($phpcsFile, $openParenthesisPointer + 1, $closeParenthesisPointer) !== null;
if ($tokens[$languageConstructPointer]['code'] === T_EXIT && $containsContentBetweenParentheses) {
return;
}
$fix = $phpcsFile->addFixableError(sprintf('Usage of language construct "%s" with parentheses is disallowed.', $tokens[$languageConstructPointer]['content']), $languageConstructPointer, self::CODE_USED_WITH_PARENTHESES);
if (!$fix) {
return;
}
$phpcsFile->fixer
->beginChangeset();
$phpcsFile->fixer
->replaceToken($openParenthesisPointer, '');
if ($tokens[$openParenthesisPointer - 1]['code'] !== T_WHITESPACE && $containsContentBetweenParentheses) {
$phpcsFile->fixer
->addContent($openParenthesisPointer, ' ');
}
$phpcsFile->fixer
->replaceToken($closeParenthesisPointer, '');
$phpcsFile->fixer
->endChangeset();
}