You are here

protected function PHP_Token_Stream::scan in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/phpunit/php-token-stream/src/Token/Stream.php \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 vendor/phpunit/php-token-stream/src/Token/Stream.php
Constructor.

File

vendor/phpunit/php-token-stream/src/Token/Stream.php, line 158

Class

PHP_Token_Stream
A stream of PHP tokens.

Code

protected function scan($sourceCode) {
  $line = 1;
  $tokens = token_get_all($sourceCode);
  $numTokens = count($tokens);
  $lastNonWhitespaceTokenWasDoubleColon = false;
  for ($i = 0; $i < $numTokens; ++$i) {
    $token = $tokens[$i];
    unset($tokens[$i]);
    if (is_array($token)) {
      $name = substr(token_name($token[0]), 2);
      $text = $token[1];
      if ($lastNonWhitespaceTokenWasDoubleColon && $name == 'CLASS') {
        $name = 'CLASS_NAME_CONSTANT';
      }
      $tokenClass = 'PHP_Token_' . $name;
    }
    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;
    }
    elseif ($tokenClass == 'PHP_Token_COMMENT' || $tokenClass == 'PHP_Token_DOC_COMMENT') {
      $this->linesOfCode['cloc'] += $lines + 1;
    }
    if ($name == 'DOUBLE_COLON') {
      $lastNonWhitespaceTokenWasDoubleColon = true;
    }
    elseif ($name != 'WHITESPACE') {
      $lastNonWhitespaceTokenWasDoubleColon = false;
    }
  }
  $this->linesOfCode['loc'] = substr_count($sourceCode, "\n");
  $this->linesOfCode['ncloc'] = $this->linesOfCode['loc'] - $this->linesOfCode['cloc'];
}