From 29e82569fafb8ad3462a3e7e8ffcf71820e5ebde Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 27 Aug 2021 11:40:10 +0200 Subject: [PATCH] Reflection: uses PhpToken --- src/Utils/Reflection.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Utils/Reflection.php b/src/Utils/Reflection.php index 1c6aeb642..cb1c10beb 100644 --- a/src/Utils/Reflection.php +++ b/src/Utils/Reflection.php @@ -277,7 +277,7 @@ public static function getUseStatements(\ReflectionClass $class): array private static function parseUseStatements(string $code, string $forClass = null): array { try { - $tokens = token_get_all($code, TOKEN_PARSE); + $tokens = \PhpToken::tokenize($code, TOKEN_PARSE); } catch (\ParseError $e) { trigger_error($e->getMessage(), E_USER_NOTICE); $tokens = []; @@ -289,7 +289,7 @@ private static function parseUseStatements(string $code, string $forClass = null while ($token = current($tokens)) { next($tokens); - switch (is_array($token) ? $token[0] : $token) { + switch ($token->id) { case T_NAMESPACE: $namespace = ltrim(self::fetch($tokens, $nameTokens) . '\\', '\\'); $uses = []; @@ -342,11 +342,11 @@ private static function parseUseStatements(string $code, string $forClass = null case T_CURLY_OPEN: case T_DOLLAR_OPEN_CURLY_BRACES: - case '{': + case ord('{'): $level++; break; - case '}': + case ord('}'): if ($level === $classLevel) { $class = $classLevel = null; } @@ -362,10 +362,9 @@ private static function fetch(array &$tokens, string|int|array $take): ?string { $res = null; while ($token = current($tokens)) { - [$token, $s] = is_array($token) ? $token : [$token, $token]; - if (in_array($token, (array) $take, true)) { - $res .= $s; - } elseif (!in_array($token, [T_DOC_COMMENT, T_WHITESPACE, T_COMMENT], true)) { + if ($token->is($take)) { + $res .= $token->text; + } elseif (!$token->is([T_DOC_COMMENT, T_WHITESPACE, T_COMMENT])) { break; } next($tokens);