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

Breadcrumb

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

function FunctionCommentSniff::processSees

Process the function "see" comments.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:

int $stackPtr The position of the current token: in the stack passed in $tokens.

int $commentStart The position in the stack where the comment started.:

Return value

void

1 call to FunctionCommentSniff::processSees()
FunctionCommentSniff::process in vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php
Processes this test, when one of its tokens is encountered.

File

vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php, line 903

Class

FunctionCommentSniff
Parses and verifies the doc comments for functions. Largely copied from PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\FunctionCommentSniff.

Namespace

Drupal\Sniffs\Commenting

Code

protected function processSees(File $phpcsFile, $stackPtr, $commentStart) {
    $tokens = $phpcsFile->getTokens();
    foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
        if ($tokens[$tag]['content'] !== '@see') {
            continue;
        }
        if ($tokens[$tag + 2]['code'] === T_DOC_COMMENT_STRING) {
            $comment = $tokens[$tag + 2]['content'];
            if (strpos($comment, ' ') !== false) {
                $error = 'The @see reference should not contain any additional text';
                $phpcsFile->addError($error, $tag, 'SeeAdditionalText');
                continue;
            }
            if (preg_match('/[\\.!\\?]$/', $comment) === 1) {
                $error = 'Trailing punctuation for @see references is not allowed.';
                $fix = $phpcsFile->addFixableError($error, $tag, 'SeePunctuation');
                if ($fix === true) {
                    // Replace the last character from the comment which is
                    // already tested to be a punctuation.
                    $content = substr($comment, 0, -1);
                    $phpcsFile->fixer
                        ->replaceToken($tag + 2, $content);
                }
                
                //end if
            }
        }
    }
    
    //end foreach
}
RSS feed
Powered by Drupal