protected function PHP_Token_Stream::scan

Scans the source for sequences of characters and converts them into a stream of tokens.

Parameters

string $sourceCode:

1 call to PHP_Token_Stream::scan()
PHP_Token_Stream::__construct in drupal/core/vendor/phpunit/php-token-stream/PHP/Token/Stream.php
Constructor.

File

drupal/core/vendor/phpunit/php-token-stream/PHP/Token/Stream.php, line 187

Class

PHP_Token_Stream
A stream of PHP tokens.

Code

protected function scan($sourceCode) {
  $line = 1;
  $tokens = token_get_all($sourceCode);
  $numTokens = count($tokens);
  for ($i = 0; $i < $numTokens; ++$i) {
    $token = $tokens[$i];
    unset($tokens[$i]);
    if (is_array($token)) {
      $text = $token[1];
      $tokenClass = 'PHP_Token_' . substr(token_name($token[0]), 2);
    }
    else {
      $text = $token;
      $tokenClass = self::$customTokens[$token];
    }
    $this->tokens[] = new $tokenClass($text, $line, $this, $i);
    $lines = substr_count($text, "\n");
    $line += $lines;
    if ($tokenClass == 'PHP_Token_HALT_COMPILER') {
      break;
    }
    else {
      if ($tokenClass == 'PHP_Token_COMMENT' || $tokenClass == 'PHP_Token_DOC_COMMENT') {
        $this->linesOfCode['cloc'] += $lines + 1;
      }
    }
  }
  $this->linesOfCode['loc'] = substr_count($sourceCode, "\n");
  $this->linesOfCode['ncloc'] = $this->linesOfCode['loc'] - $this->linesOfCode['cloc'];
}