function CastSpacingSniff::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/
squizlabs/ php_codesniffer/ src/ Standards/ Squiz/ Sniffs/ WhiteSpace/ CastSpacingSniff.php, line 41
Class
Namespace
PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpaceCode
public function process(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();
$content = $tokens[$stackPtr]['content'];
$expected = str_replace(' ', '', $content);
$expected = str_replace("\t", '', $expected);
if ($content !== $expected) {
$error = 'Cast statements must not contain whitespace; expected "%s" but found "%s"';
$data = [
$expected,
$content,
];
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'ContainsWhiteSpace', $data);
if ($fix === true) {
$phpcsFile->fixer
->replaceToken($stackPtr, $expected);
}
}
}