function NewWithoutParenthesesSniff::process
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
Parameters
int $newPointer:
Overrides Sniff::process
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ ControlStructures/ NewWithoutParenthesesSniff.php, line 41
Class
Namespace
SlevomatCodingStandard\Sniffs\ControlStructuresCode
public function process(File $phpcsFile, $newPointer) : void {
$tokens = $phpcsFile->getTokens();
/** @var int $nextPointer */
$nextPointer = TokenHelper::findNextEffective($phpcsFile, $newPointer + 1);
if ($tokens[$nextPointer]['code'] === T_ANON_CLASS) {
return;
}
$parenthesisOpenerPointer = $nextPointer + 1;
do {
/** @var int $parenthesisOpenerPointer */
$parenthesisOpenerPointer = TokenHelper::findNext($phpcsFile, [
T_OPEN_PARENTHESIS,
T_SEMICOLON,
T_COMMA,
T_INLINE_THEN,
T_INLINE_ELSE,
T_COALESCE,
T_CLOSE_SHORT_ARRAY,
T_CLOSE_SQUARE_BRACKET,
T_CLOSE_PARENTHESIS,
T_DOUBLE_ARROW,
], $parenthesisOpenerPointer);
if ($tokens[$parenthesisOpenerPointer]['code'] !== T_CLOSE_SQUARE_BRACKET || $tokens[$parenthesisOpenerPointer]['bracket_opener'] <= $newPointer) {
break;
}
$parenthesisOpenerPointer++;
} while (true);
if ($tokens[$parenthesisOpenerPointer]['code'] !== T_OPEN_PARENTHESIS) {
return;
}
$nextPointer = TokenHelper::findNextNonWhitespace($phpcsFile, $parenthesisOpenerPointer + 1);
if ($nextPointer !== $tokens[$parenthesisOpenerPointer]['parenthesis_closer']) {
return;
}
$fix = $phpcsFile->addFixableError('Useless parentheses in "new".', $newPointer, self::CODE_USELESS_PARENTHESES);
if (!$fix) {
return;
}
$phpcsFile->fixer
->beginChangeset();
FixerHelper::removeBetweenIncluding($phpcsFile, $parenthesisOpenerPointer, $tokens[$parenthesisOpenerPointer]['parenthesis_closer']);
$phpcsFile->fixer
->endChangeset();
}