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

Breadcrumb

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

function DocCommentSpacingSniff::checkLinesBeforeFirstContent

1 call to DocCommentSpacingSniff::checkLinesBeforeFirstContent()
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 164

Class

DocCommentSpacingSniff

Namespace

SlevomatCodingStandard\Sniffs\Commenting

Code

private function checkLinesBeforeFirstContent(File $phpcsFile, int $docCommentOpenerPointer, int $firstContentStartPointer) : void {
    $tokens = $phpcsFile->getTokens();
    $whitespaceBeforeFirstContent = substr($tokens[$docCommentOpenerPointer]['content'], 0, strlen('/**'));
    $whitespaceBeforeFirstContent .= TokenHelper::getContent($phpcsFile, $docCommentOpenerPointer + 1, $firstContentStartPointer - 1);
    $linesCountBeforeFirstContent = max(substr_count($whitespaceBeforeFirstContent, $phpcsFile->eolChar) - 1, 0);
    if ($linesCountBeforeFirstContent === $this->linesCountBeforeFirstContent) {
        return;
    }
    $fix = $phpcsFile->addFixableError(sprintf('Expected %d line%s before first content, found %d.', $this->linesCountBeforeFirstContent, $this->linesCountBeforeFirstContent === 1 ? '' : 's', $linesCountBeforeFirstContent), $firstContentStartPointer, self::CODE_INCORRECT_LINES_COUNT_BEFORE_FIRST_CONTENT);
    if (!$fix) {
        return;
    }
    $indentation = IndentationHelper::getIndentation($phpcsFile, $docCommentOpenerPointer);
    $phpcsFile->fixer
        ->beginChangeset();
    FixerHelper::change($phpcsFile, $docCommentOpenerPointer, $firstContentStartPointer - 1, '/**' . $phpcsFile->eolChar);
    for ($i = 1; $i <= $this->linesCountBeforeFirstContent; $i++) {
        $phpcsFile->fixer
            ->addContent($docCommentOpenerPointer, sprintf('%s *%s', $indentation, $phpcsFile->eolChar));
    }
    $phpcsFile->fixer
        ->addContentBefore($firstContentStartPointer, $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