Skip to content
This repository has been archived by the owner on Jul 26, 2021. It is now read-only.

Commit

Permalink
Merge branch '1.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 27, 2017
2 parents 90c9540 + e03f8f6 commit deabde0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/Token/Stream.php
Expand Up @@ -150,6 +150,7 @@ public function getFilename()
*/
protected function scan($sourceCode)
{
$id = 0;
$line = 1;
$tokens = token_get_all($sourceCode);
$numTokens = count($tokens);
Expand All @@ -158,7 +159,7 @@ protected function scan($sourceCode)

for ($i = 0; $i < $numTokens; ++$i) {
$token = $tokens[$i];
unset($tokens[$i]);
$skip = 0;

if (is_array($token)) {
$name = substr(token_name($token[0]), 2);
Expand All @@ -167,12 +168,8 @@ protected function scan($sourceCode)
if ($lastNonWhitespaceTokenWasDoubleColon && $name == 'CLASS') {
$name = 'CLASS_NAME_CONSTANT';
} elseif ($name == 'USE' && isset($tokens[$i + 2][0]) && $tokens[$i + 2][0] == T_FUNCTION) {
unset($tokens[$i + 1]);
unset($tokens[$i + 2]);

$i += 2;

$name = 'USE_FUNCTION';
$skip = 2;
}

$tokenClass = 'PHP_Token_' . $name;
Expand All @@ -181,7 +178,7 @@ protected function scan($sourceCode)
$tokenClass = self::$customTokens[$token];
}

$this->tokens[] = new $tokenClass($text, $line, $this, $i);
$this->tokens[] = new $tokenClass($text, $line, $this, $id++);
$lines = substr_count($text, "\n");
$line += $lines;

Expand All @@ -197,6 +194,8 @@ protected function scan($sourceCode)
} elseif ($name != 'WHITESPACE') {
$lastNonWhitespaceTokenWasDoubleColon = false;
}

$i += $skip;
}

$this->linesOfCode['loc'] = substr_count($sourceCode, "\n");
Expand Down
1 change: 1 addition & 0 deletions tests/Token/ClassTest.php
Expand Up @@ -115,5 +115,6 @@ public function testImportedFunctionsAreHandledCorrectly()
$ts = new PHP_Token_Stream(TEST_FILES_PATH . 'classUsesNamespacedFunction.php');

$this->assertEmpty($ts->getFunctions());
$this->assertCount(1, $ts->getClasses());
}
}

0 comments on commit deabde0

Please sign in to comment.