function MultiLineFunctionDeclarationSniff::processMultiLineDeclaration
Same name in this branch
- 11.1.x vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Functions/MultiLineFunctionDeclarationSniff.php \PHP_CodeSniffer\Standards\Squiz\Sniffs\Functions\MultiLineFunctionDeclarationSniff::processMultiLineDeclaration()
Processes multi-line declarations.
Parameters
\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:
int $stackPtr The position of the current token: in the stack passed in $tokens.
array<int, array<string, mixed>> $tokens The stack of tokens that make up: the file.
Return value
void
Overrides MultiLineFunctionDeclarationSniff::processMultiLineDeclaration
File
-
vendor/
drupal/ coder/ coder_sniffer/ Drupal/ Sniffs/ Functions/ MultiLineFunctionDeclarationSniff.php, line 96
Class
- MultiLineFunctionDeclarationSniff
- Multi-line function declarations need to have a trailing comma on the last parameter. Modified from Squiz, whenever there is a function declaration closing parenthesis on a new line we treat it as multi-line.
Namespace
Drupal\Sniffs\FunctionsCode
public function processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens) {
// We do everything the grandparent sniff does, and a bit more.
PearFunctionDeclarationSniff::processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens);
$openBracket = $tokens[$stackPtr]['parenthesis_opener'];
$this->processBracket($phpcsFile, $openBracket, $tokens, 'function');
// Trailing commas on the last function parameter are only possible in
// PHP 8.0+.
if (version_compare(PHP_VERSION, '8.0.0') < 0) {
return;
}
$function = $tokens[$stackPtr];
$lastTrailingComma = $phpcsFile->findPrevious(Tokens::$emptyTokens, $function['parenthesis_closer'] - 1, $function['parenthesis_opener'], true);
if ($tokens[$lastTrailingComma]['code'] !== T_COMMA) {
$error = 'Multi-line function declarations must have a trailing comma after the last parameter';
$fix = $phpcsFile->addFixableError($error, $lastTrailingComma, 'MissingTrailingComma');
if ($fix === true) {
$phpcsFile->fixer
->addContent($lastTrailingComma, ',');
}
}
}