Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. RequireAbstractOrFinalSniff.php

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

RequireAbstractOrFinalSniff

Namespace

SlevomatCodingStandard\Sniffs\Classes

Code

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();
}
RSS feed
Powered by Drupal