function DisallowTrailingCommaInDeclarationSniff::process
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
Parameters
int $functionPointer:
Overrides Sniff::process
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Functions/ DisallowTrailingCommaInDeclarationSniff.php, line 32
Class
Namespace
SlevomatCodingStandard\Sniffs\FunctionsCode
public function process(File $phpcsFile, $functionPointer) : void {
$tokens = $phpcsFile->getTokens();
$parenthesisOpenerPointer = $tokens[$functionPointer]['parenthesis_opener'];
$parenthesisCloserPointer = $tokens[$functionPointer]['parenthesis_closer'];
$pointerBeforeParenthesisCloser = TokenHelper::findPreviousExcluding($phpcsFile, T_WHITESPACE, $parenthesisCloserPointer - 1, $parenthesisOpenerPointer);
if ($tokens[$pointerBeforeParenthesisCloser]['code'] !== T_COMMA) {
return;
}
if ($this->onlySingleLine && $tokens[$parenthesisOpenerPointer]['line'] !== $tokens[$parenthesisCloserPointer]['line']) {
return;
}
$fix = $phpcsFile->addFixableError('Trailing comma after the last parameter in function declaration is disallowed.', $pointerBeforeParenthesisCloser, self::CODE_DISALLOWED_TRAILING_COMMA);
if (!$fix) {
return;
}
$phpcsFile->fixer
->beginChangeset();
$phpcsFile->fixer
->replaceToken($pointerBeforeParenthesisCloser, '');
if ($tokens[$pointerBeforeParenthesisCloser]['line'] === $tokens[$parenthesisCloserPointer]['line']) {
FixerHelper::removeBetween($phpcsFile, $pointerBeforeParenthesisCloser, $parenthesisCloserPointer);
}
$phpcsFile->fixer
->endChangeset();
}