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

Breadcrumb

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

function AbstractPropertyConstantAndEnumCaseSpacing::process

* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

Parameters

int $pointer:

Overrides Sniff::process

4 calls to AbstractPropertyConstantAndEnumCaseSpacing::process()
ConstantSpacingSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Classes/ConstantSpacingSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
ConstantSpacingSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Classes/ConstantSpacingSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
PropertySpacingSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Classes/PropertySpacingSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
PropertySpacingSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Classes/PropertySpacingSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
2 methods override AbstractPropertyConstantAndEnumCaseSpacing::process()
ConstantSpacingSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Classes/ConstantSpacingSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
PropertySpacingSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Classes/PropertySpacingSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Classes/AbstractPropertyConstantAndEnumCaseSpacing.php, line 56

Class

AbstractPropertyConstantAndEnumCaseSpacing
@internal

Namespace

SlevomatCodingStandard\Sniffs\Classes

Code

public function process(File $phpcsFile, $pointer) : int {
    $this->minLinesCountBeforeWithComment = SniffSettingsHelper::normalizeInteger($this->minLinesCountBeforeWithComment);
    $this->maxLinesCountBeforeWithComment = SniffSettingsHelper::normalizeInteger($this->maxLinesCountBeforeWithComment);
    $this->minLinesCountBeforeWithoutComment = SniffSettingsHelper::normalizeInteger($this->minLinesCountBeforeWithoutComment);
    $this->maxLinesCountBeforeWithoutComment = SniffSettingsHelper::normalizeInteger($this->maxLinesCountBeforeWithoutComment);
    $tokens = $phpcsFile->getTokens();
    $classPointer = ClassHelper::getClassPointer($phpcsFile, $pointer);
    $semicolonPointer = TokenHelper::findNext($phpcsFile, [
        T_SEMICOLON,
    ], $pointer + 1);
    assert($semicolonPointer !== null);
    $firstOnLinePointer = TokenHelper::findFirstTokenOnNextLine($phpcsFile, $semicolonPointer);
    assert($firstOnLinePointer !== null);
    $nextFunctionPointer = TokenHelper::findNext($phpcsFile, [
        T_FUNCTION,
        T_ENUM_CASE,
        T_CONST,
        T_VARIABLE,
        T_USE,
    ], $firstOnLinePointer + 1);
    if ($nextFunctionPointer === null || $tokens[$nextFunctionPointer]['code'] === T_FUNCTION || $tokens[$nextFunctionPointer]['conditions'] !== $tokens[$pointer]['conditions']) {
        return $nextFunctionPointer ?? $firstOnLinePointer;
    }
    $types = [
        T_COMMENT,
        T_DOC_COMMENT_OPEN_TAG,
        T_ATTRIBUTE,
        T_ENUM_CASE,
        T_CONST,
        T_VAR,
        T_PUBLIC,
        T_PROTECTED,
        T_PRIVATE,
        T_READONLY,
        T_STATIC,
        T_USE,
    ];
    $nextPointer = TokenHelper::findNext($phpcsFile, $types, $firstOnLinePointer + 1, $tokens[$classPointer]['scope_closer']);
    if (!$this->isNextMemberValid($phpcsFile, $nextPointer)) {
        return $nextPointer;
    }
    $linesBetween = $tokens[$nextPointer]['line'] - $tokens[$semicolonPointer]['line'] - 1;
    if (in_array($tokens[$nextPointer]['code'], [
        T_DOC_COMMENT_OPEN_TAG,
        T_COMMENT,
        T_ATTRIBUTE,
    ], true)) {
        $minExpectedLines = $this->minLinesCountBeforeWithComment;
        $maxExpectedLines = $this->maxLinesCountBeforeWithComment;
    }
    else {
        $minExpectedLines = $this->minLinesCountBeforeWithoutComment;
        $maxExpectedLines = $this->maxLinesCountBeforeWithoutComment;
    }
    if ($linesBetween >= $minExpectedLines && $linesBetween <= $maxExpectedLines) {
        return $firstOnLinePointer;
    }
    $fix = $this->addError($phpcsFile, $pointer, $minExpectedLines, $maxExpectedLines, $linesBetween);
    if (!$fix) {
        return $firstOnLinePointer;
    }
    if ($linesBetween > $maxExpectedLines) {
        $lastPointerOnLine = TokenHelper::findLastTokenOnLine($phpcsFile, $semicolonPointer);
        $firstPointerOnNextLine = TokenHelper::findFirstTokenOnLine($phpcsFile, $nextPointer);
        $phpcsFile->fixer
            ->beginChangeset();
        if ($maxExpectedLines > 0) {
            $phpcsFile->fixer
                ->addContent($lastPointerOnLine, str_repeat($phpcsFile->eolChar, $maxExpectedLines));
        }
        FixerHelper::removeBetween($phpcsFile, $lastPointerOnLine, $firstPointerOnNextLine);
        $phpcsFile->fixer
            ->endChangeset();
    }
    else {
        $phpcsFile->fixer
            ->beginChangeset();
        for ($i = 0; $i < $minExpectedLines; $i++) {
            $phpcsFile->fixer
                ->addNewlineBefore($firstOnLinePointer);
        }
        $phpcsFile->fixer
            ->endChangeset();
    }
    return $firstOnLinePointer;
}

API Navigation

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