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

Breadcrumb

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

function ClassLengthSniff::process

* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

Parameters

int $pointer:

Overrides Sniff::process

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Classes/ClassLengthSniff.php, line 42

Class

ClassLengthSniff

Namespace

SlevomatCodingStandard\Sniffs\Classes

Code

public function process(File $phpcsFile, $pointer) : void {
    $this->maxLinesLength = SniffSettingsHelper::normalizeInteger($this->maxLinesLength);
    $flags = array_keys(array_filter([
        FunctionHelper::LINE_INCLUDE_COMMENT => $this->includeComments,
        FunctionHelper::LINE_INCLUDE_WHITESPACE => $this->includeWhitespace,
    ]));
    $flags = array_reduce($flags, static function ($carry, $flag) : int {
        return $carry | $flag;
    }, 0);
    $length = FunctionHelper::getLineCount($phpcsFile, $pointer, $flags);
    if ($length <= $this->maxLinesLength) {
        return;
    }
    $errorMessage = sprintf('Your class is too long. Currently using %d lines. Can be up to %d lines.', $length, $this->maxLinesLength);
    $phpcsFile->addError($errorMessage, $pointer, self::CODE_CLASS_TOO_LONG);
}
RSS feed
Powered by Drupal