private function getClassNamesFromTokens(array $tokens) : array
    {
        for ($i = 0;$i < count($tokens);$i++) {
            // Skip literals
            if (is_string($tokens[$i])) {
                continue;
            }

            $className = '';

            switch ($tokens[$i][0]) {
                case T_NAMESPACE:
                    $namespace = '';

                    // Collect all the namespace parts and separators
                    while (isset($tokens[++$i][1])) {
                        if (in_array($tokens[$i][0], [T_NS_SEPARATOR, T_STRING])) {
                            $namespace .= $tokens[$i][1];
                        }
                    }

                    break;
                case T_CLASS:
                    $isClassConstant = false;

                    // Scan previous tokens to see if they're double colons, which would mean this is a class constant
                    for ($j = $i - 1;$j >= 0;$j--) {
                        if (!isset($tokens[$j][1])) {
                            break;
                        }

                        if ($tokens[$j][0] === T_DOUBLE_COLON) {
                            $isClassConstant = true;
                            break 2;
                        } elseif ($tokens[$j][0] === T_WHITESPACE) {
                            // Since we found whitespace, then we know this isn't a class constant
                            break;
                        }
                    }

                    // Get the class name
                    while (isset($tokens[++$i][1])) {
                        if ($tokens[$i][0] === T_STRING) {
                            $className .= $tokens[$i][1];
                            break;
                        }
                    }

                    $classNames[] = ltrim($namespace . '\\' . $className, '\\');
                    break 2;
            }
        }

        return $classNames;
    }
private function getClassNamesFromTokens(array $tokens) : array
    {
        for ($i = 0;$i < count($tokens);$i++) {
            // Skip literals
            if (is_string($tokens[$i])) {
                continue;
            }

            $className = '';

            switch ($tokens[$i][0]) {
                case T_NAMESPACE:
                    $namespace = '';

                    // Collect all the namespace parts and separators
                    while (isset($tokens[++$i][1])) {
                        if (in_array($tokens[$i][0], [T_NS_SEPARATOR, T_STRING])) {
                            $namespace .= $tokens[$i][1];
                        }
                    }

                    break;
                case T_CLASS:
                    $isClassConstant = false;

                    // Scan previous tokens to see if they're double colons, which would mean this is a class constant
                    for ($j = $i - 1;$j >= 0;$j--) {
                        if (!isset($tokens[$j][1])) {
                            break;
                        }

                        if ($tokens[$j][0] === T_DOUBLE_COLON) {
                            $isClassConstant = true;
                            break 2;
                        } elseif ($tokens[$j][0] === T_WHITESPACE) {
                            // Since we found whitespace, then we know this isn't a class constant
                            break;
                        }
                    }

                    // Get the class name
                    while (isset($tokens[++$i][1])) {
                        if ($tokens[$i][0] === T_STRING) {
                            $className .= $tokens[$i][1];
                            break;
                        }
                    }

                    $classNames[] = ltrim($namespace . '\\' . $className, '\\');
                    break 2;
            }
        }

        return $classNames;
    }
private function getClassNamesFromTokens ( array $ tokens ) : array { for ( $ i = 0 ; $ i < count ( $ tokens ) ; $ i ++ ) { // Skip literals if ( is_string ( $ tokens [ $ i ] ) ) { continue ; } $ className = '' ; switch ( $ tokens [ $ i ] [ 0 ] ) { case T_NAMESPACE : $ namespace = '' ; // Collect all the namespace parts and separators while ( isset ( $ tokens [ ++ $ i ] [ 1 ] ) ) { if ( in_array ( $ tokens [ $ i ] [ 0 ] , [ T_NS_SEPARATOR , T_STRING ] ) ) { $ namespace .= $ tokens [ $ i ] [ 1 ] ; } } break ; case T_CLASS : $ isClassConstant = false ; // Scan previous tokens to see if they're double colons, which would mean this is a class constant for ( $ j = $ i - 1 ; $ j >= 0 ; $ j -- ) { if ( ! isset ( $ tokens [ $ j ] [ 1 ] ) ) { break ; } if ( $ tokens [ $ j ] [ 0 ] === T_DOUBLE_COLON ) { $ isClassConstant = true ; break 2 ; } elseif ( $ tokens [ $ j ] [ 0 ] === T_WHITESPACE ) { // Since we found whitespace, then we know this isn't a class constant break ; } } // Get the class name while ( isset ( $ tokens [ ++ $ i ] [ 1 ] ) ) { if ( $ tokens [ $ i ] [ 0 ] === T_STRING ) { $ className .= $ tokens [ $ i ] [ 1 ] ; break ; } } $ classNames [ ] = ltrim ( $ namespace . '\\' . $ className , '\\' ) ; break 2 ; } } return $ classNames ; }
Gets the class names from a list of tokens
This will work even if multiple classes are defined in each file

@param string[] $tokens The array of tokens
@return string[] The names of the classes
Gets the class names from a list of tokens This will work even if multiple classes are defined in each file