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

Breadcrumb

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

function Comment::processLine

Process a single line of a comment.

Parameters

string $string The comment string being tokenized.:

string $eolChar The EOL character to use for splitting strings.:

int $start The position in the string to start processing.:

int $end The position in the string to end processing.:

Return value

array<int, array<string, string|int>>

1 call to Comment::processLine()
Comment::tokenizeString in vendor/squizlabs/php_codesniffer/src/Tokenizers/Comment.php
Creates an array of tokens when given some PHP code.

File

vendor/squizlabs/php_codesniffer/src/Tokenizers/Comment.php, line 184

Class

Comment

Namespace

PHP_CodeSniffer\Tokenizers

Code

private function processLine($string, $eolChar, $start, $end) {
    $tokens = [];
    // Collect content padding.
    $space = $this->collectWhitespace($string, $start, $end);
    if ($space !== null) {
        $tokens[] = $space;
        $start += strlen($space['content']);
    }
    if (isset($string[$start]) === false) {
        return $tokens;
    }
    if ($string[$start] === '@') {
        // The content up until the first whitespace is the tag name.
        $matches = [];
        preg_match('/@[^\\s]+/', $string, $matches, 0, $start);
        if (isset($matches[0]) === true && substr(strtolower($matches[0]), 0, 7) !== '@phpcs:') {
            $tagName = $matches[0];
            $start += strlen($tagName);
            $tokens[] = [
                'content' => $tagName,
                'code' => T_DOC_COMMENT_TAG,
                'type' => 'T_DOC_COMMENT_TAG',
            ];
            // Then there will be some whitespace.
            $space = $this->collectWhitespace($string, $start, $end);
            if ($space !== null) {
                $tokens[] = $space;
                $start += strlen($space['content']);
            }
        }
    }
    
    //end if
    // Process the rest of the line.
    $eol = strpos($string, $eolChar, $start);
    if ($eol === false) {
        $eol = $end;
    }
    if ($eol > $start) {
        $tokens[] = [
            'content' => substr($string, $start, $eol - $start),
            'code' => T_DOC_COMMENT_STRING,
            'type' => 'T_DOC_COMMENT_STRING',
        ];
    }
    if ($eol !== $end) {
        $tokens[] = [
            'content' => substr($string, $eol, strlen($eolChar)),
            'code' => T_DOC_COMMENT_WHITESPACE,
            'type' => 'T_DOC_COMMENT_WHITESPACE',
        ];
    }
    return $tokens;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal