function RequireNumericLiteralSeparatorSniff::process
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
Parameters
int $numberPointer:
Overrides Sniff::process
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Numbers/ RequireNumericLiteralSeparatorSniff.php, line 45
Class
Namespace
SlevomatCodingStandard\Sniffs\NumbersCode
public function process(File $phpcsFile, $numberPointer) : void {
$this->enable = SniffSettingsHelper::isEnabledByPhpVersion($this->enable, 70400);
$this->minDigitsBeforeDecimalPoint = SniffSettingsHelper::normalizeInteger($this->minDigitsBeforeDecimalPoint);
$this->minDigitsAfterDecimalPoint = SniffSettingsHelper::normalizeInteger($this->minDigitsAfterDecimalPoint);
if (!$this->enable) {
return;
}
$tokens = $phpcsFile->getTokens();
$number = $tokens[$numberPointer]['content'];
if (strpos($tokens[$numberPointer]['content'], '_') !== false) {
return;
}
if ($this->ignoreOctalNumbers && preg_match('~^0[0-7]+$~', $number) === 1) {
return;
}
$regexp = '~(?:^\\d{' . $this->minDigitsBeforeDecimalPoint . '}|\\.\\d{' . $this->minDigitsAfterDecimalPoint . '})~';
if (preg_match($regexp, $number) === 0) {
return;
}
$phpcsFile->addError('Use of numeric literal separator is required.', $numberPointer, self::CODE_REQUIRED_NUMERIC_LITERAL_SEPARATOR);
}