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

Breadcrumb

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

function InlineCommentSniff::isInCodeExample

Determines if a comment line is part of an

/

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.

Return value

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

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

File

vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php, line 467

Class

InlineCommentSniff
\Drupal\Sniffs\Commenting\InlineCommentSniff.

Namespace

Drupal\Sniffs\Commenting

Code

protected function isInCodeExample(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    if ($tokens[$stackPtr]['content'] === '// @code' . $phpcsFile->eolChar) {
        return true;
    }
    $prevComment = $stackPtr;
    $lastComment = $stackPtr;
    while (($prevComment = $phpcsFile->findPrevious([
        T_COMMENT,
    ], $lastComment - 1, null, false)) !== false) {
        if ($tokens[$prevComment]['line'] !== $tokens[$lastComment]['line'] - 1) {
            return false;
        }
        if ($tokens[$prevComment]['content'] === '// @code' . $phpcsFile->eolChar) {
            return true;
        }
        if ($tokens[$prevComment]['content'] === '// @endcode' . $phpcsFile->eolChar) {
            return false;
        }
        $lastComment = $prevComment;
    }
    return false;
}
RSS feed
Powered by Drupal