Skip to content

Commit 7ef28a0

Browse files
committed
fix tokenizer to not use token_get_all()
1 parent 97b59e4 commit 7ef28a0

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/PhpTokenizer.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,24 @@ public static function getTokensArrayFromContent(
108108

109109
// Convert tokens from token_get_all to Token instances,
110110
// skipping whitespace and (usually, when parseContext is null) comments.
111-
$tokens = \array_values($tokens);
112-
$tokenCount = \count($tokens);
111+
$keys = \array_keys($tokens);
112+
$tokenCount = \count($keys);
113113
for ($i = 0; $i < $tokenCount; $i++) {
114-
$token = $tokens[$i];
114+
$token = $tokens[$keys[$i]];
115115
if (\is_array($token)) {
116116
$tokenKind = $token[0];
117117
$strlen = \strlen($token[1]);
118118
} else {
119-
if ($token === '|' && $i + 1 < $tokenCount && $tokens[$i + 1] === '>') {
120-
$pos += 1; // '|'
121-
$i++;
122-
$pos += 1; // '>'
123-
$arr[] = new Token(TokenKind::PipeToken, $fullStart, $start, $pos - $fullStart);
124-
$start = $fullStart = $pos;
125-
continue;
119+
if ($token === '|' && $i + 1 < $tokenCount) {
120+
$nextToken = $tokens[$keys[$i + 1]];
121+
if (!\is_array($nextToken) && $nextToken === '>') {
122+
$pos += 1; // '|'
123+
$i++;
124+
$pos += 1; // '>'
125+
$arr[] = new Token(TokenKind::PipeToken, $fullStart, $start, $pos - $fullStart);
126+
$start = $fullStart = $pos;
127+
continue;
128+
}
126129
}
127130
$pos += \strlen($token);
128131
$newTokenKind = self::TOKEN_MAP[$token] ?? TokenKind::Unknown;

0 commit comments

Comments
 (0)