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

Breadcrumb

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

function DocCommentSpacingSniff::checkLinesAfterLastContent

1 call to DocCommentSpacingSniff::checkLinesAfterLastContent()
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 720

Class

DocCommentSpacingSniff

Namespace

SlevomatCodingStandard\Sniffs\Commenting

Code

private function checkLinesAfterLastContent(File $phpcsFile, int $docCommentOpenerPointer, int $docCommentCloserPointer, int $lastContentEndPointer) : void {
    $whitespaceAfterLastContent = TokenHelper::getContent($phpcsFile, $lastContentEndPointer + 1, $docCommentCloserPointer);
    $linesCountAfterLastContent = max(substr_count($whitespaceAfterLastContent, $phpcsFile->eolChar) - 1, 0);
    if ($linesCountAfterLastContent === $this->linesCountAfterLastContent) {
        return;
    }
    $fix = $phpcsFile->addFixableError(sprintf('Expected %d line%s after last content, found %d.', $this->linesCountAfterLastContent, $this->linesCountAfterLastContent === 1 ? '' : 's', $linesCountAfterLastContent), $lastContentEndPointer, self::CODE_INCORRECT_LINES_COUNT_AFTER_LAST_CONTENT);
    if (!$fix) {
        return;
    }
    $indentation = IndentationHelper::getIndentation($phpcsFile, $docCommentOpenerPointer);
    $phpcsFile->fixer
        ->beginChangeset();
    FixerHelper::removeBetween($phpcsFile, $lastContentEndPointer, $docCommentCloserPointer);
    $phpcsFile->fixer
        ->addNewline($lastContentEndPointer);
    for ($i = 1; $i <= $this->linesCountAfterLastContent; $i++) {
        $phpcsFile->fixer
            ->addContent($lastContentEndPointer, sprintf('%s *%s', $indentation, $phpcsFile->eolChar));
    }
    $phpcsFile->fixer
        ->addContentBefore($docCommentCloserPointer, $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