public function CommaSniff::process in Coder 8.2
Same name and namespace in other branches
- 8.3 coder_sniffer/Drupal/Sniffs/WhiteSpace/CommaSniff.php \Drupal\Sniffs\WhiteSpace\CommaSniff::process()
- 8.3.x coder_sniffer/Drupal/Sniffs/WhiteSpace/CommaSniff.php \Drupal\Sniffs\WhiteSpace\CommaSniff::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
File
- coder_sniffer/
Drupal/ Sniffs/ WhiteSpace/ CommaSniff.php, line 49
Class
Namespace
Drupal\Sniffs\WhiteSpaceCode
public function process(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile
->getTokens();
if (isset($tokens[$stackPtr + 1]) === false) {
return;
}
if ($tokens[$stackPtr + 1]['code'] !== T_WHITESPACE && $tokens[$stackPtr + 1]['code'] !== T_COMMA && $tokens[$stackPtr + 1]['code'] !== T_CLOSE_PARENTHESIS) {
$error = 'Expected one space after the comma, 0 found';
$fix = $phpcsFile
->addFixableError($error, $stackPtr, 'NoSpace');
if ($fix === true) {
$phpcsFile->fixer
->addContent($stackPtr, ' ');
}
return;
}
if ($tokens[$stackPtr + 1]['code'] === T_WHITESPACE && isset($tokens[$stackPtr + 2]) === true && $tokens[$stackPtr + 2]['line'] === $tokens[$stackPtr + 1]['line'] && $tokens[$stackPtr + 1]['content'] !== ' ') {
$error = 'Expected one space after the comma, %s found';
$fix = $phpcsFile
->addFixableError($error, $stackPtr, 'TooManySpaces', array(
strlen($tokens[$stackPtr + 1]['content']),
));
if ($fix === true) {
$phpcsFile->fixer
->replaceToken($stackPtr + 1, ' ');
}
}
}