@@ -284,7 +284,7 @@ public static function getUseStatements(\ReflectionClass $class): array
284284 private static function parseUseStatements (string $ code , ?string $ forClass = null ): array
285285 {
286286 try {
287- $ tokens = token_get_all ($ code , TOKEN_PARSE );
287+ $ tokens = \PhpToken:: tokenize ($ code , TOKEN_PARSE );
288288 } catch (\ParseError $ e ) {
289289 trigger_error ($ e ->getMessage (), E_USER_NOTICE );
290290 $ tokens = [];
@@ -297,7 +297,7 @@ private static function parseUseStatements(string $code, ?string $forClass = nul
297297
298298 while ($ token = current ($ tokens )) {
299299 next ($ tokens );
300- switch (is_array ( $ token) ? $ token [ 0 ] : $ token ) {
300+ switch ($ token-> id ) {
301301 case T_NAMESPACE :
302302 $ namespace = ltrim (self ::fetch ($ tokens , $ nameTokens ) . '\\' , '\\' );
303303 $ uses = [];
@@ -353,11 +353,11 @@ private static function parseUseStatements(string $code, ?string $forClass = nul
353353
354354 case T_CURLY_OPEN :
355355 case T_DOLLAR_OPEN_CURLY_BRACES :
356- case '{ ' :
356+ case ord ( '{ ' ) :
357357 $ level ++;
358358 break ;
359359
360- case '} ' :
360+ case ord ( '} ' ) :
361361 if ($ level === $ classLevel ) {
362362 $ class = $ classLevel = null ;
363363 }
@@ -374,10 +374,9 @@ private static function fetch(array &$tokens, string|int|array $take): ?string
374374 {
375375 $ res = null ;
376376 while ($ token = current ($ tokens )) {
377- [$ token , $ s ] = is_array ($ token ) ? $ token : [$ token , $ token ];
378- if (in_array ($ token , (array ) $ take , true )) {
379- $ res .= $ s ;
380- } elseif (!in_array ($ token , [T_DOC_COMMENT , T_WHITESPACE , T_COMMENT ], true )) {
377+ if ($ token ->is ($ take )) {
378+ $ res .= $ token ->text ;
379+ } elseif (!$ token ->is ([T_DOC_COMMENT , T_WHITESPACE , T_COMMENT ])) {
381380 break ;
382381 }
383382
0 commit comments