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

Breadcrumb

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

function RequireSingleLineMethodSignatureSniff::process

* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

Parameters

int $methodPointer:

Overrides Sniff::process

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Classes/RequireSingleLineMethodSignatureSniff.php, line 39

Class

RequireSingleLineMethodSignatureSniff

Namespace

SlevomatCodingStandard\Sniffs\Classes

Code

public function process(File $phpcsFile, $methodPointer) : void {
    $this->maxLineLength = SniffSettingsHelper::normalizeInteger($this->maxLineLength);
    if (!FunctionHelper::isMethod($phpcsFile, $methodPointer)) {
        return;
    }
    $tokens = $phpcsFile->getTokens();
    [
        $signatureStartPointer,
        $signatureEndPointer,
    ] = $this->getSignatureStartAndEndPointers($phpcsFile, $methodPointer);
    if ($tokens[$signatureStartPointer]['line'] === $tokens[$signatureEndPointer]['line']) {
        return;
    }
    $signature = $this->getSignature($phpcsFile, $signatureStartPointer, $signatureEndPointer);
    $signatureWithoutTabIndentation = $this->getSignatureWithoutTabs($phpcsFile, $signature);
    $methodName = FunctionHelper::getName($phpcsFile, $methodPointer);
    if (count($this->includedMethodPatterns) !== 0 && !$this->isMethodNameInPatterns($methodName, $this->getIncludedMethodNormalizedPatterns())) {
        return;
    }
    if (count($this->excludedMethodPatterns) !== 0 && $this->isMethodNameInPatterns($methodName, $this->getExcludedMethodNormalizedPatterns())) {
        return;
    }
    if ($this->maxLineLength !== 0 && strlen($signatureWithoutTabIndentation) > $this->maxLineLength) {
        return;
    }
    $error = sprintf('Signature of method "%s" should be placed on a single line.', $methodName);
    $fix = $phpcsFile->addFixableError($error, $methodPointer, self::CODE_REQUIRED_SINGLE_LINE_SIGNATURE);
    if (!$fix) {
        return;
    }
    $phpcsFile->fixer
        ->beginChangeset();
    FixerHelper::change($phpcsFile, $signatureStartPointer, $signatureEndPointer, $signature);
    $phpcsFile->fixer
        ->endChangeset();
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal