function DisallowLateStaticBindingForConstantsSniff::process
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
Parameters
int $staticPointer:
Overrides Sniff::process
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Classes/ DisallowLateStaticBindingForConstantsSniff.php, line 33
Class
Namespace
SlevomatCodingStandard\Sniffs\ClassesCode
public function process(File $phpcsFile, $staticPointer) : void {
$tokens = $phpcsFile->getTokens();
$doubleColonPointer = TokenHelper::findNextEffective($phpcsFile, $staticPointer + 1);
if ($tokens[$doubleColonPointer]['code'] !== T_DOUBLE_COLON) {
return;
}
$stringPointer = TokenHelper::findNextEffective($phpcsFile, $doubleColonPointer + 1);
if ($tokens[$stringPointer]['code'] !== T_STRING) {
return;
}
if (strtolower($tokens[$stringPointer]['content']) === 'class') {
return;
}
$pointerAfterString = TokenHelper::findNextEffective($phpcsFile, $stringPointer + 1);
if ($tokens[$pointerAfterString]['code'] === T_OPEN_PARENTHESIS) {
return;
}
$fix = $phpcsFile->addFixableError('Late static binding for constants is disallowed.', $staticPointer, self::CODE_DISALLOWED_LATE_STATIC_BINDING_FOR_CONSTANT);
if (!$fix) {
return;
}
$phpcsFile->fixer
->beginChangeset();
$phpcsFile->fixer
->replaceToken($staticPointer, 'self');
$phpcsFile->fixer
->endChangeset();
}