*/ public function register() { return [ \T_LNUMBER, \T_DNUMBER, ]; } /** * Processes this test, when one of its tokens is encountered. * * @since 10.0.0 * * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. * @param int $stackPtr The position of the current token in the * stack passed in $tokens. * * @return int|void Integer stack pointer to skip forward or void to continue * normal file processing. */ public function process(File $phpcsFile, $stackPtr) { if (ScannedCode::shouldRunOnOrBelow('7.3') === false) { return; } try { $numberInfo = Numbers::getCompleteNumber($phpcsFile, $stackPtr); if ($numberInfo['orig_content'] === $numberInfo['content']) { // Content is the same, i.e. no underscores found, move on. return; } $phpcsFile->addError( 'The use of underscore separators in numeric literals is not supported in PHP 7.3 or lower. Found: %s', $stackPtr, 'Found', [$numberInfo['orig_content']] ); // Skip past the parts we've already taken into account to prevent double reporting. return ($numberInfo['last_token'] + 1); } catch (RuntimeException $e) { // Running on an unsupported PHPCS version. return; } } }