Opis\Closure\ReflectionClosure::fetchItems PHP Method

fetchItems() protected method

protected fetchItems ( )
    protected function fetchItems()
    {
        $key = $this->getHashedFileName();
        $classes = array();
        $functions = array();
        $constants = array();
        $structures = array();
        $tokens = $this->getFileTokens();
        $open = 0;
        $state = 'start';
        $prefix = '';
        $name = '';
        $alias = '';
        $isFunc = $isConst = false;
        $startLine = $endLine = 0;
        $structType = $structName = '';
        $structIgnore = false;
        $hasTraitSupport = defined('T_TRAIT');
        foreach ($tokens as $token) {
            $is_array = is_array($token);
            switch ($state) {
                case 'start':
                    if ($is_array) {
                        switch ($token[0]) {
                            case T_CLASS:
                            case T_INTERFACE:
                                $state = 'before_structure';
                                $startLine = $token[2];
                                $structType = $token[0] == T_CLASS ? 'class' : 'interface';
                                break;
                            case T_USE:
                                $state = 'use';
                                $prefix = $name = $alias = '';
                                $isFunc = $isConst = false;
                                break;
                            case T_FUNCTION:
                                $state = 'structure';
                                $structIgnore = true;
                                break;
                            default:
                                if ($hasTraitSupport && $token[0] == T_TRAIT) {
                                    $state = 'before_structure';
                                    $startLine = $token[2];
                                    $structType = 'trait';
                                }
                                break;
                        }
                    }
                    break;
                case 'use':
                    if ($is_array) {
                        switch ($token[0]) {
                            case T_FUNCTION:
                                $isFunc = true;
                                break;
                            case T_CONST:
                                $isConst = true;
                                break;
                            case T_NS_SEPARATOR:
                                $name .= $token[1];
                                break;
                            case T_STRING:
                                $name .= $token[1];
                                $alias = $token[1];
                                break;
                            case T_AS:
                                if ($name[0] !== '\\' && $prefix === '') {
                                    $name = '\\' . $name;
                                }
                                $state = 'alias';
                                break;
                        }
                    } else {
                        if ($name[0] !== '\\' && $prefix === '') {
                            $name = '\\' . $name;
                        }
                        if ($token == '{') {
                            $prefix = $name;
                            $name = '';
                        } else {
                            if ($isFunc) {
                                $functions[$alias] = $prefix . $name;
                            } elseif ($isConst) {
                                $constants[$alias] = $prefix . $name;
                            } else {
                                $classes[$alias] = $prefix . $name;
                            }
                            $name = '';
                            $state = $token == ',' ? 'use' : 'start';
                        }
                    }
                    break;
                case 'alias':
                    if ($is_array) {
                        if ($token[0] == T_STRING) {
                            $alias = $token[1];
                        }
                    } else {
                        if ($isFunc) {
                            $functions[$alias] = $prefix . $name;
                        } elseif ($isConst) {
                            $constants[$alias] = $prefix . $name;
                        } else {
                            $classes[$alias] = $prefix . $name;
                        }
                        $name = '';
                        $state = $token == ',' ? 'use' : 'start';
                    }
                    break;
                case 'before_structure':
                    if ($is_array && $token[0] == T_STRING) {
                        $structName = $token[1];
                        $state = 'structure';
                    }
                    break;
                case 'structure':
                    if (!$is_array) {
                        if ($token === '{') {
                            $open++;
                        } elseif ($token === '}') {
                            if (--$open == 0) {
                                if (!$structIgnore) {
                                    $structures[] = array('type' => $structType, 'name' => $structName, 'start' => $startLine, 'end' => $endLine);
                                }
                                $structIgnore = false;
                                $state = 'start';
                            }
                        }
                    } else {
                        if ($token[0] === T_CURLY_OPEN || $token[0] === T_DOLLAR_OPEN_CURLY_BRACES) {
                            $open++;
                        }
                        $endLine = $token[2];
                    }
                    break;
            }
        }
        static::$classes[$key] = $classes;
        static::$functions[$key] = $functions;
        static::$constants[$key] = $constants;
        static::$structures[$key] = $structures;
    }