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

Breadcrumb

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

function File::getTokensAsString

Returns the content of the tokens from the specified start position in the token stack for the specified length.

Parameters

int $start The position to start from in the token stack.:

int $length The length of tokens to traverse from the start pos.:

bool $origContent Whether the original content or the tab replaced: content should be used.

Return value

string The token contents.

Throws

\PHP_CodeSniffer\Exceptions\RuntimeException If the specified position does not exist.

3 calls to File::getTokensAsString()
File::findExtendedClassName in vendor/squizlabs/php_codesniffer/src/Files/File.php
Returns the name of the class that the specified class extends. (works for classes, anonymous classes and interfaces)
File::findImplementedInterfaceNames in vendor/squizlabs/php_codesniffer/src/Files/File.php
Returns the names of the interfaces that the specified class or enum implements.
File::getMethodParameters in vendor/squizlabs/php_codesniffer/src/Files/File.php
Returns the method parameters for the specified function token.

File

vendor/squizlabs/php_codesniffer/src/Files/File.php, line 2223

Class

File

Namespace

PHP_CodeSniffer\Files

Code

public function getTokensAsString($start, $length, $origContent = false) {
    if (is_int($start) === false || isset($this->tokens[$start]) === false) {
        throw new RuntimeException('The $start position for getTokensAsString() must exist in the token stack');
    }
    if (is_int($length) === false || $length <= 0) {
        return '';
    }
    $str = '';
    $end = $start + $length;
    if ($end > $this->numTokens) {
        $end = $this->numTokens;
    }
    for ($i = $start; $i < $end; $i++) {
        // If tabs are being converted to spaces by the tokeniser, the
        // original content should be used instead of the converted content.
        if ($origContent === true && isset($this->tokens[$i]['orig_content']) === true) {
            $str .= $this->tokens[$i]['orig_content'];
        }
        else {
            $str .= $this->tokens[$i]['content'];
        }
    }
    return $str;
}

API Navigation

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