You are here

protected function FunctionCommentSniff::processSees in Coder 8.2

Same name and namespace in other branches
  1. 8.3 coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php \Drupal\Sniffs\Commenting\FunctionCommentSniff::processSees()
  2. 8.3.x coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php \Drupal\Sniffs\Commenting\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 coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php
Processes this test, when one of its tokens is encountered.

File

coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php, line 889

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
}