class DisallowNumericLiteralSeparatorSniff
Hierarchy
- class \SlevomatCodingStandard\Sniffs\Numbers\DisallowNumericLiteralSeparatorSniff implements \PHP_CodeSniffer\Sniffs\Sniff
Expanded class hierarchy of DisallowNumericLiteralSeparatorSniff
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Numbers/ DisallowNumericLiteralSeparatorSniff.php, line 12
Namespace
SlevomatCodingStandard\Sniffs\NumbersView source
class DisallowNumericLiteralSeparatorSniff implements Sniff {
public const CODE_DISALLOWED_NUMERIC_LITERAL_SEPARATOR = 'DisallowedNumericLiteralSeparator';
/**
* @return array<int, (int|string)>
*/
public function register() : array {
return [
T_LNUMBER,
T_DNUMBER,
];
}
/**
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
* @param int $numberPointer
*/
public function process(File $phpcsFile, $numberPointer) : void {
$tokens = $phpcsFile->getTokens();
if (strpos($tokens[$numberPointer]['content'], '_') === false) {
return;
}
$fix = $phpcsFile->addFixableError('Use of numeric literal separator is disallowed.', $numberPointer, self::CODE_DISALLOWED_NUMERIC_LITERAL_SEPARATOR);
if (!$fix) {
return;
}
$phpcsFile->fixer
->beginChangeset();
$phpcsFile->fixer
->replaceToken($numberPointer, str_replace('_', '', $tokens[$numberPointer]['content']));
$phpcsFile->fixer
->endChangeset();
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
DisallowNumericLiteralSeparatorSniff::CODE_DISALLOWED_NUMERIC_LITERAL_SEPARATOR | public | constant | ||
DisallowNumericLiteralSeparatorSniff::process | public | function | * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint * |
Overrides Sniff::process |
DisallowNumericLiteralSeparatorSniff::register | public | function | * | Overrides Sniff::register |