function ByteOrderMarkSniff::process
Processes this sniff, 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
int
Overrides Sniff::process
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Standards/ Generic/ Sniffs/ Files/ ByteOrderMarkSniff.php, line 54
Class
Namespace
PHP_CodeSniffer\Standards\Generic\Sniffs\FilesCode
public function process(File $phpcsFile, $stackPtr) {
// The BOM will be the very first token in the file.
if ($stackPtr !== 0) {
return $phpcsFile->numTokens;
}
$tokens = $phpcsFile->getTokens();
foreach ($this->bomDefinitions as $bomName => $expectedBomHex) {
$bomByteLength = strlen($expectedBomHex) / 2;
$htmlBomHex = bin2hex(substr($tokens[$stackPtr]['content'], 0, $bomByteLength));
if ($htmlBomHex === $expectedBomHex) {
$errorData = [
$bomName,
];
$error = 'File contains %s byte order mark, which may corrupt your application';
$phpcsFile->addError($error, $stackPtr, 'Found', $errorData);
$phpcsFile->recordMetric($stackPtr, 'Using byte order mark', 'yes');
return $phpcsFile->numTokens;
}
}
$phpcsFile->recordMetric($stackPtr, 'Using byte order mark', 'no');
return $phpcsFile->numTokens;
}