function RequireTrailingCommaInDeclarationSniff::process
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
Parameters
int $functionPointer:
Overrides Sniff::process
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Functions/ RequireTrailingCommaInDeclarationSniff.php, line 31
Class
Namespace
SlevomatCodingStandard\Sniffs\FunctionsCode
public function process(File $phpcsFile, $functionPointer) : void {
$this->enable = SniffSettingsHelper::isEnabledByPhpVersion($this->enable, 80000);
if (!$this->enable) {
return;
}
$tokens = $phpcsFile->getTokens();
$parenthesisOpenerPointer = $tokens[$functionPointer]['parenthesis_opener'];
$parenthesisCloserPointer = $tokens[$functionPointer]['parenthesis_closer'];
if ($tokens[$parenthesisOpenerPointer]['line'] === $tokens[$parenthesisCloserPointer]['line']) {
return;
}
$pointerBeforeParenthesisCloser = TokenHelper::findPreviousEffective($phpcsFile, $parenthesisCloserPointer - 1, $parenthesisOpenerPointer);
if ($pointerBeforeParenthesisCloser === $parenthesisOpenerPointer) {
return;
}
if ($tokens[$pointerBeforeParenthesisCloser]['code'] === T_COMMA) {
return;
}
$fix = $phpcsFile->addFixableError('Multi-line function declaration must have a trailing comma after the last parameter.', $pointerBeforeParenthesisCloser, self::CODE_MISSING_TRAILING_COMMA);
if (!$fix) {
return;
}
$phpcsFile->fixer
->beginChangeset();
$phpcsFile->fixer
->addContent($pointerBeforeParenthesisCloser, ',');
$phpcsFile->fixer
->endChangeset();
}