function MultiLineFunctionDeclarationSniff::processBracket
Processes the contents of a single set of brackets.
Parameters
\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:
int $openBracket The position of the open bracket: in the stack passed in $tokens.
array $tokens The stack of tokens that make up: the file.
string $type The type of the token the brackets: belong to (function or use).
Return value
void
2 calls to MultiLineFunctionDeclarationSniff::processBracket()
- MultiLineFunctionDeclarationSniff::processMultiLineDeclaration in vendor/
drupal/ coder/ coder_sniffer/ Drupal/ Sniffs/ Functions/ MultiLineFunctionDeclarationSniff.php - Processes multi-line declarations.
- MultiLineFunctionDeclarationSniff::processMultiLineDeclaration in vendor/
squizlabs/ php_codesniffer/ src/ Standards/ Squiz/ Sniffs/ Functions/ MultiLineFunctionDeclarationSniff.php - Processes multi-line declarations.
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Standards/ Squiz/ Sniffs/ Functions/ MultiLineFunctionDeclarationSniff.php, line 191
Class
Namespace
PHP_CodeSniffer\Standards\Squiz\Sniffs\FunctionsCode
public function processBracket($phpcsFile, $openBracket, $tokens, $type = 'function') {
$errorPrefix = '';
if ($type === 'use') {
$errorPrefix = 'Use';
}
$closeBracket = $tokens[$openBracket]['parenthesis_closer'];
// The open bracket should be the last thing on the line.
if ($tokens[$openBracket]['line'] !== $tokens[$closeBracket]['line']) {
$next = $phpcsFile->findNext(Tokens::$emptyTokens, $openBracket + 1, null, true);
if ($tokens[$next]['line'] === $tokens[$openBracket]['line']) {
$error = 'The first parameter of a multi-line ' . $type . ' declaration must be on the line after the opening bracket';
$fix = $phpcsFile->addFixableError($error, $next, $errorPrefix . 'FirstParamSpacing');
if ($fix === true) {
if ($tokens[$next]['line'] === $tokens[$openBracket]['line']) {
$phpcsFile->fixer
->addNewline($openBracket);
}
else {
$phpcsFile->fixer
->beginChangeset();
for ($x = $openBracket; $x < $next; $x++) {
if ($tokens[$x]['line'] === $tokens[$openBracket]['line']) {
continue;
}
if ($tokens[$x]['line'] === $tokens[$next]['line']) {
break;
}
}
$phpcsFile->fixer
->endChangeset();
}
}
}
//end if
}
//end if
// Each line between the brackets should contain a single parameter.
for ($i = $openBracket + 1; $i < $closeBracket; $i++) {
// Skip brackets, like arrays, as they can contain commas.
if (isset($tokens[$i]['bracket_closer']) === true) {
$i = $tokens[$i]['bracket_closer'];
continue;
}
if (isset($tokens[$i]['parenthesis_closer']) === true) {
$i = $tokens[$i]['parenthesis_closer'];
continue;
}
if (isset($tokens[$i]['attribute_closer']) === true) {
$i = $tokens[$i]['attribute_closer'];
continue;
}
if ($tokens[$i]['code'] !== T_COMMA) {
continue;
}
$next = $phpcsFile->findNext(Tokens::$emptyTokens, $i + 1, null, true);
if ($tokens[$next]['line'] === $tokens[$i]['line']) {
$error = 'Multi-line ' . $type . ' declarations must define one parameter per line';
$fix = $phpcsFile->addFixableError($error, $next, $errorPrefix . 'OneParamPerLine');
if ($fix === true) {
$phpcsFile->fixer
->addNewline($i);
}
}
}
//end for
}