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

Breadcrumb

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

function DocCommentSpacingSniff::checkLinesBetweenAnnotationsGroups

*

Parameters

list<list<Annotation>> $annotationsGroups:

1 call to DocCommentSpacingSniff::checkLinesBetweenAnnotationsGroups()
DocCommentSpacingSniff::checkAnnotationsGroups in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Commenting/DocCommentSpacingSniff.php
*

File

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

Class

DocCommentSpacingSniff

Namespace

SlevomatCodingStandard\Sniffs\Commenting

Code

private function checkLinesBetweenAnnotationsGroups(File $phpcsFile, int $docCommentOpenerPointer, array $annotationsGroups) : void {
    $tokens = $phpcsFile->getTokens();
    $previousAnnotationsGroup = null;
    foreach ($annotationsGroups as $annotationsGroup) {
        if ($previousAnnotationsGroup === null) {
            $previousAnnotationsGroup = $annotationsGroup;
            continue;
        }
        $lastAnnotationInPreviousGroup = $previousAnnotationsGroup[count($previousAnnotationsGroup) - 1];
        $firstAnnotationInActualGroup = $annotationsGroup[0];
        $actualLinesCountBetweenAnnotationsGroups = $tokens[$firstAnnotationInActualGroup->getStartPointer()]['line'] - $tokens[$lastAnnotationInPreviousGroup->getEndPointer()]['line'] - 1;
        if ($actualLinesCountBetweenAnnotationsGroups === $this->linesCountBetweenAnnotationsGroups) {
            $previousAnnotationsGroup = $annotationsGroup;
            continue;
        }
        $fix = $phpcsFile->addFixableError(sprintf('Expected %d line%s between annotations groups, found %d.', $this->linesCountBetweenAnnotationsGroups, $this->linesCountBetweenAnnotationsGroups === 1 ? '' : 's', $actualLinesCountBetweenAnnotationsGroups), $firstAnnotationInActualGroup->getStartPointer(), self::CODE_INCORRECT_LINES_COUNT_BETWEEN_ANNOTATIONS_GROUPS);
        if (!$fix) {
            $previousAnnotationsGroup = $annotationsGroup;
            continue;
        }
        $indentation = IndentationHelper::getIndentation($phpcsFile, $docCommentOpenerPointer);
        $phpcsFile->fixer
            ->beginChangeset();
        $phpcsFile->fixer
            ->addNewline($lastAnnotationInPreviousGroup->getEndPointer());
        FixerHelper::removeBetween($phpcsFile, $lastAnnotationInPreviousGroup->getEndPointer(), $firstAnnotationInActualGroup->getStartPointer());
        for ($i = 1; $i <= $this->linesCountBetweenAnnotationsGroups; $i++) {
            $phpcsFile->fixer
                ->addContent($lastAnnotationInPreviousGroup->getEndPointer(), sprintf('%s *%s', $indentation, $phpcsFile->eolChar));
        }
        $phpcsFile->fixer
            ->addContentBefore($firstAnnotationInActualGroup->getStartPointer(), $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