From f598aecfcc5d5800f9587f4fe4f60b5580289c6c Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 8 Sep 2020 17:03:48 +0200 Subject: [PATCH] fix parsing tokens on PHP 8 --- src/Types/ContextFactory.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Types/ContextFactory.php b/src/Types/ContextFactory.php index 596cf61..c59bc04 100644 --- a/src/Types/ContextFactory.php +++ b/src/Types/ContextFactory.php @@ -221,7 +221,7 @@ private function parseNamespace(ArrayIterator $tokens) : string $this->skipToNextStringOrNamespaceSeparator($tokens); $name = ''; - while ($tokens->valid() && in_array($tokens->current()[0], [T_STRING, T_NS_SEPARATOR], true)) { + while ($tokens->valid() && (in_array($tokens->current()[0], [T_STRING, T_NS_SEPARATOR], true) || defined('T_NAME_QUALIFIED') && T_NAME_QUALIFIED === $tokens->current()[0])) { $name .= $tokens->current()[1]; $tokens->next(); } @@ -268,6 +268,14 @@ private function skipToNextStringOrNamespaceSeparator(ArrayIterator $tokens) : v break; } + if (defined('T_NAME_QUALIFIED') && T_NAME_QUALIFIED === $currentToken[0]) { + break; + } + + if (defined('T_NAME_FULLY_QUALIFIED') && T_NAME_FULLY_QUALIFIED === $currentToken[0]) { + break; + } + $tokens->next(); } } @@ -317,6 +325,13 @@ private function extractUseStatements(ArrayIterator $tokens) : array $state = 'end'; break; default: + if (defined('T_NAME_QUALIFIED') && T_NAME_QUALIFIED === $tokenId) { + $currentNs .= (string)$tokenValue; + $currentAlias = substr($tokenValue, strrpos($tokenValue, '\\') + 1); + } elseif (defined('T_NAME_FULLY_QUALIFIED') && T_NAME_FULLY_QUALIFIED === $tokenId) { + $currentNs .= (string) $tokenValue; + $currentAlias = substr($tokenValue, strrpos($tokenValue, '\\') + 1); + } break; }