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

Breadcrumb

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

function DocCommentSpacingSniff::checkLinesBetweenDescriptionAndFirstAnnotation

1 call to DocCommentSpacingSniff::checkLinesBetweenDescriptionAndFirstAnnotation()
DocCommentSpacingSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Commenting/DocCommentSpacingSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Commenting/DocCommentSpacingSniff.php, line 206

Class

DocCommentSpacingSniff

Namespace

SlevomatCodingStandard\Sniffs\Commenting

Code

private function checkLinesBetweenDescriptionAndFirstAnnotation(File $phpcsFile, int $docCommentOpenerPointer, int $firstContentStartPointer, int $firstContentEndPointer, ?int $firstAnnotationPointer) : void {
    if ($firstAnnotationPointer === null) {
        return;
    }
    if ($firstContentStartPointer === $firstAnnotationPointer) {
        return;
    }
    $tokens = $phpcsFile->getTokens();
    preg_match('~(\\s+)$~', $tokens[$firstContentEndPointer]['content'], $matches);
    $whitespaceBetweenDescriptionAndFirstAnnotation = $matches[1] ?? '';
    $whitespaceBetweenDescriptionAndFirstAnnotation .= TokenHelper::getContent($phpcsFile, $firstContentEndPointer + 1, $firstAnnotationPointer - 1);
    $linesCountBetweenDescriptionAndAnnotations = max(substr_count($whitespaceBetweenDescriptionAndFirstAnnotation, $phpcsFile->eolChar) - 1, 0);
    if ($linesCountBetweenDescriptionAndAnnotations === $this->linesCountBetweenDescriptionAndAnnotations) {
        return;
    }
    $fix = $phpcsFile->addFixableError(sprintf('Expected %d line%s between description and annotations, found %d.', $this->linesCountBetweenDescriptionAndAnnotations, $this->linesCountBetweenDescriptionAndAnnotations === 1 ? '' : 's', $linesCountBetweenDescriptionAndAnnotations), $firstAnnotationPointer, self::CODE_INCORRECT_LINES_COUNT_BETWEEN_DESCRIPTION_AND_ANNOTATIONS);
    if (!$fix) {
        return;
    }
    $indentation = IndentationHelper::getIndentation($phpcsFile, $docCommentOpenerPointer);
    $phpcsFile->fixer
        ->beginChangeset();
    $phpcsFile->fixer
        ->addNewline($firstContentEndPointer);
    FixerHelper::removeBetween($phpcsFile, $firstContentEndPointer, $firstAnnotationPointer);
    for ($i = 1; $i <= $this->linesCountBetweenDescriptionAndAnnotations; $i++) {
        $phpcsFile->fixer
            ->addContent($firstContentEndPointer, sprintf('%s *%s', $indentation, $phpcsFile->eolChar));
    }
    $phpcsFile->fixer
        ->addContentBefore($firstAnnotationPointer, $indentation . ' * ');
    $phpcsFile->fixer
        ->endChangeset();
}

API Navigation

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