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

Breadcrumb

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

function InlineDocCommentDeclarationSniff::process

* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

Parameters

int $commentOpenPointer:

Overrides Sniff::process

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Commenting/InlineDocCommentDeclarationSniff.php, line 70

Class

InlineDocCommentDeclarationSniff

Namespace

SlevomatCodingStandard\Sniffs\Commenting

Code

public function process(File $phpcsFile, $commentOpenPointer) : void {
    $tokens = $phpcsFile->getTokens();
    $commentClosePointer = $tokens[$commentOpenPointer]['code'] === T_COMMENT ? $commentOpenPointer : $tokens[$commentOpenPointer]['comment_closer'];
    $pointerAfterCommentClosePointer = TokenHelper::findNextEffective($phpcsFile, $commentClosePointer + 1);
    if ($pointerAfterCommentClosePointer !== null) {
        do {
            if ($tokens[$pointerAfterCommentClosePointer]['code'] !== T_ATTRIBUTE) {
                break;
            }
            $pointerAfterCommentClosePointer = TokenHelper::findNextEffective($phpcsFile, $tokens[$pointerAfterCommentClosePointer]['attribute_closer'] + 1);
        } while (true);
        if (in_array($tokens[$pointerAfterCommentClosePointer]['code'], [
            T_PRIVATE,
            T_PROTECTED,
            T_PUBLIC,
            T_READONLY,
            T_FINAL,
            T_CONST,
        ], true)) {
            return;
        }
        if ($tokens[$pointerAfterCommentClosePointer]['code'] === T_STATIC) {
            $pointerAfterStatic = TokenHelper::findNextEffective($phpcsFile, $pointerAfterCommentClosePointer + 1);
            if (in_array($tokens[$pointerAfterStatic]['code'], [
                T_PRIVATE,
                T_PROTECTED,
                T_PUBLIC,
                T_READONLY,
            ], true)) {
                return;
            }
            if ($tokens[$pointerAfterStatic]['code'] === T_VARIABLE && PropertyHelper::isProperty($phpcsFile, $pointerAfterStatic)) {
                return;
            }
        }
    }
    if ($tokens[$commentOpenPointer]['code'] === T_COMMENT) {
        $this->checkCommentType($phpcsFile, $commentOpenPointer);
        return;
    }
    
    /** @var list<Annotation<VarTagValueNode>> $annotations */
    $annotations = AnnotationHelper::getAnnotations($phpcsFile, $commentOpenPointer, '@var');
    if ($annotations === []) {
        return;
    }
    if ($this->allowDocCommentAboveReturn) {
        $pointerAfterCommentClosePointer = TokenHelper::findNextEffective($phpcsFile, $commentClosePointer + 1);
        if ($tokens[$pointerAfterCommentClosePointer]['code'] === T_RETURN) {
            return;
        }
    }
    $this->checkFormat($phpcsFile, $annotations);
    $this->checkVariable($phpcsFile, $annotations, $commentOpenPointer, $commentClosePointer);
}
RSS feed
Powered by Drupal