function RequireAbstractOrFinalSniff::process
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
Parameters
int $classPointer:
Overrides Sniff::process
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Classes/ RequireAbstractOrFinalSniff.php, line 33
Class
Namespace
SlevomatCodingStandard\Sniffs\ClassesCode
public function process(File $phpcsFile, $classPointer) : void {
$tokens = $phpcsFile->getTokens();
$previousPointer = TokenHelper::findPreviousEffective($phpcsFile, $classPointer - 1);
if ($tokens[$previousPointer]['code'] === T_READONLY) {
$previousPointer = TokenHelper::findPreviousEffective($phpcsFile, $previousPointer - 1);
}
if (in_array($tokens[$previousPointer]['code'], [
T_ABSTRACT,
T_FINAL,
], true)) {
return;
}
$fix = $phpcsFile->addFixableError('All classes should be declared using either the "abstract" or "final" keyword.', $classPointer, self::CODE_NO_ABSTRACT_OR_FINAL);
if (!$fix) {
return;
}
$phpcsFile->fixer
->beginChangeset();
$phpcsFile->fixer
->addContentBefore($classPointer, 'final ');
$phpcsFile->fixer
->endChangeset();
}