Skip to content

Commit f598aec

Browse files
committed
fix parsing tokens on PHP 8
1 parent e21c0bd commit f598aec

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/Types/ContextFactory.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private function parseNamespace(ArrayIterator $tokens) : string
221221
$this->skipToNextStringOrNamespaceSeparator($tokens);
222222

223223
$name = '';
224-
while ($tokens->valid() && in_array($tokens->current()[0], [T_STRING, T_NS_SEPARATOR], true)) {
224+
while ($tokens->valid() && (in_array($tokens->current()[0], [T_STRING, T_NS_SEPARATOR], true) || defined('T_NAME_QUALIFIED') && T_NAME_QUALIFIED === $tokens->current()[0])) {
225225
$name .= $tokens->current()[1];
226226
$tokens->next();
227227
}
@@ -268,6 +268,14 @@ private function skipToNextStringOrNamespaceSeparator(ArrayIterator $tokens) : v
268268
break;
269269
}
270270

271+
if (defined('T_NAME_QUALIFIED') && T_NAME_QUALIFIED === $currentToken[0]) {
272+
break;
273+
}
274+
275+
if (defined('T_NAME_FULLY_QUALIFIED') && T_NAME_FULLY_QUALIFIED === $currentToken[0]) {
276+
break;
277+
}
278+
271279
$tokens->next();
272280
}
273281
}
@@ -317,6 +325,13 @@ private function extractUseStatements(ArrayIterator $tokens) : array
317325
$state = 'end';
318326
break;
319327
default:
328+
if (defined('T_NAME_QUALIFIED') && T_NAME_QUALIFIED === $tokenId) {
329+
$currentNs .= (string)$tokenValue;
330+
$currentAlias = substr($tokenValue, strrpos($tokenValue, '\\') + 1);
331+
} elseif (defined('T_NAME_FULLY_QUALIFIED') && T_NAME_FULLY_QUALIFIED === $tokenId) {
332+
$currentNs .= (string) $tokenValue;
333+
$currentAlias = substr($tokenValue, strrpos($tokenValue, '\\') + 1);
334+
}
320335
break;
321336
}
322337

0 commit comments

Comments
 (0)