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

Breadcrumb

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

function AbstractRequireOneLineDocComment::process

* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

Parameters

int $docCommentStartPointer:

Overrides Sniff::process

2 calls to AbstractRequireOneLineDocComment::process()
RequireOneLinePropertyDocCommentSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Commenting/RequireOneLinePropertyDocCommentSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
RequireOneLinePropertyDocCommentSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Commenting/RequireOneLinePropertyDocCommentSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
1 method overrides AbstractRequireOneLineDocComment::process()
RequireOneLinePropertyDocCommentSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Commenting/RequireOneLinePropertyDocCommentSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Commenting/AbstractRequireOneLineDocComment.php, line 36

Class

AbstractRequireOneLineDocComment
@internal

Namespace

SlevomatCodingStandard\Sniffs\Commenting

Code

public function process(File $phpcsFile, $docCommentStartPointer) : void {
    $tokens = $phpcsFile->getTokens();
    // Only validate properties without description
    if (DocCommentHelper::hasDocCommentDescription($phpcsFile, $docCommentStartPointer)) {
        return;
    }
    $docCommentEndPointer = $tokens[$docCommentStartPointer]['comment_closer'];
    $lineDifference = $tokens[$docCommentEndPointer]['line'] - $tokens[$docCommentStartPointer]['line'];
    // Already one-line
    if ($lineDifference === 0) {
        return;
    }
    // Ignore empty lines
    $currentLinePointer = $docCommentStartPointer;
    do {
        $currentLinePointer = TokenHelper::findFirstTokenOnNextLine($phpcsFile, $currentLinePointer);
        if ($currentLinePointer === null || $currentLinePointer >= $docCommentEndPointer) {
            break;
        }
        $types = [
            T_DOC_COMMENT_STAR,
            T_DOC_COMMENT_CLOSE_TAG,
        ];
        $startingPointer = TokenHelper::findNext($phpcsFile, $types, $currentLinePointer, $docCommentEndPointer);
        if ($startingPointer === null || $tokens[$startingPointer]['code'] === T_DOC_COMMENT_CLOSE_TAG) {
            break;
        }
        $nextEffectivePointer = TokenHelper::findNextExcluding($phpcsFile, [
            T_DOC_COMMENT_WHITESPACE,
        ], $startingPointer + 1, $docCommentEndPointer + 1);
        if ($tokens[$currentLinePointer]['line'] === $tokens[$nextEffectivePointer]['line']) {
            continue;
        }
        $lineDifference--;
    } while (true);
    // Looks like a compound doc-comment
    if ($lineDifference > 2) {
        return;
    }
    $fix = $this->addError($phpcsFile, $docCommentStartPointer);
    if (!$fix) {
        return;
    }
    $contentStartPointer = TokenHelper::findNextExcluding($phpcsFile, [
        T_DOC_COMMENT_WHITESPACE,
        T_DOC_COMMENT_STAR,
    ], $docCommentStartPointer + 1, $docCommentEndPointer);
    $contentEndPointer = TokenHelper::findPreviousExcluding($phpcsFile, [
        T_DOC_COMMENT_WHITESPACE,
        T_DOC_COMMENT_STAR,
    ], $docCommentEndPointer - 1, $docCommentStartPointer);
    if ($contentStartPointer === null) {
        FixerHelper::removeBetween($phpcsFile, $docCommentStartPointer, $docCommentEndPointer);
        return;
    }
    $phpcsFile->fixer
        ->beginChangeset();
    for ($i = $docCommentStartPointer + 1; $i < $docCommentEndPointer; $i++) {
        if ($i >= $contentStartPointer && $i <= $contentEndPointer) {
            if ($i === $contentEndPointer) {
                $phpcsFile->fixer
                    ->replaceToken($i, rtrim($phpcsFile->fixer
                    ->getTokenContent($i), ' '));
            }
            continue;
        }
        $phpcsFile->fixer
            ->replaceToken($i, '');
    }
    $phpcsFile->fixer
        ->addContentBefore($contentStartPointer, ' ');
    $phpcsFile->fixer
        ->addContentBefore($docCommentEndPointer, ' ');
    $phpcsFile->fixer
        ->endChangeset();
}

API Navigation

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