function CloseBracketSpacingSniff::process
Processes this test, when one of its tokens is encountered.
Parameters
\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:
int $stackPtr The position of the current token: in the stack passed in $tokens.
Return value
void
Overrides Sniff::process
File
-
vendor/
drupal/ coder/ coder_sniffer/ Drupal/ Sniffs/ WhiteSpace/ CloseBracketSpacingSniff.php, line 54
Class
- CloseBracketSpacingSniff
- Checks that there is no white space before a closing bracket, for ")" and "}". Square Brackets are handled by \PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayBracketSpacingSniff.
Namespace
Drupal\Sniffs\WhiteSpaceCode
public function process(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();
// Ignore curly brackets in javascript files.
if ($tokens[$stackPtr]['code'] === T_CLOSE_CURLY_BRACKET && $phpcsFile->tokenizerType === 'JS') {
return;
}
if (isset($tokens[$stackPtr - 1]) === true && $tokens[$stackPtr - 1]['code'] === T_WHITESPACE) {
$before = $phpcsFile->findPrevious(Tokens::$emptyTokens, $stackPtr - 1, null, true);
if ($before !== false && $tokens[$stackPtr]['line'] === $tokens[$before]['line']) {
$error = 'There should be no white space before a closing "%s"';
$fix = $phpcsFile->addFixableError($error, $stackPtr - 1, 'ClosingWhitespace', [
$tokens[$stackPtr]['content'],
]);
if ($fix === true) {
$phpcsFile->fixer
->replaceToken($stackPtr - 1, '');
}
}
}
}