protected static function discoverClassesInFile($phpCode)
    {
        $classes          = array();
        $tokens           = token_get_all($phpCode);
        $gettingClassname = $gettingNamespace = false;
        $namespace        = '';
        $lastToken        = null;

        // Run through all tokens
        for ($t = 0, $tokenCount = count($tokens); $t < $tokenCount; ++$t) {
            $token = $tokens[$t];

            // If this is a namespace token
            if (is_array($token) && ($token[0] == T_NAMESPACE)) {
                $namespace        = '';
                $gettingNamespace = true;
                continue;
            }

            // If this is a class name token
            if (is_array($token) && ($token[0] == T_CLASS) && (!is_array(
                        $lastToken
                    ) || ($lastToken[0] !== T_PAAMAYIM_NEKUDOTAYIM))) {
                $gettingClassname = true;
            }

            // If we're getting a namespace
            if ($gettingNamespace === true) {
                if (is_array($token) && in_array($token[0], [T_STRING, T_NS_SEPARATOR])) {
                    $namespace .= $token[1];
                } elseif ($token === ';') {
                    $gettingNamespace = false;
                }

                // Else if we're getting the class name
            } elseif ($gettingClassname === true) {
                if (is_array($token) && ($token[0] == T_STRING)) {
                    $classes[]        = ($namespace ? $namespace.'\\' : '').$token[1];
                    $gettingClassname = false;
                }
            }

            $lastToken = $token;
        }

        return $classes;
    }