You are here

protected function FunctionCommentSniff::isInCodeExample in Coder 8.3.x

Same name and namespace in other branches
  1. 8.3 coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php \Drupal\Sniffs\Commenting\FunctionCommentSniff::isInCodeExample()

Determines if a comment line is part of an

?>
<?php/?><?php

example.

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 of the start of the comment: in the stack passed in $tokens.

Return value

boolean Returns true if the comment line is within a @code block, false otherwise.

1 call to FunctionCommentSniff::isInCodeExample()
FunctionCommentSniff::processParams in coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php
Process the function parameter comments.

File

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

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 isInCodeExample(File $phpcsFile, $stackPtr, $commentStart) {
  $tokens = $phpcsFile
    ->getTokens();
  if (strpos($tokens[$stackPtr]['content'], '@code') !== false) {
    return true;
  }
  $prevTag = $phpcsFile
    ->findPrevious([
    T_DOC_COMMENT_TAG,
  ], $stackPtr - 1, $commentStart);
  if ($prevTag === false) {
    return false;
  }
  if ($tokens[$prevTag]['content'] === '@code') {
    return true;
  }
  return false;
}