PDepend\Source\Language\PHP\AbstractPHPParser::parse PHP Method

parse() public method

Parses the contents of the tokenizer and generates a node tree based on the found tokens.
public parse ( ) : void
return void
    public function parse()
    {
        $this->compilationUnit = $this->tokenizer->getSourceFile();
        $this->compilationUnit->setCache($this->cache)->setId($this->idBuilder->forFile($this->compilationUnit));
        if ($this->compilationUnit->getFileName() === 'php://stdin') {
            $hash = md5('php://stdin');
        } else {
            $hash = md5_file($this->compilationUnit->getFileName());
        }
        if ($this->cache->restore($this->compilationUnit->getId(), $hash)) {
            return;
        }
        $this->cache->remove($this->compilationUnit->getId());
        $this->setUpEnvironment();
        $this->tokenStack->push();
        Log::debug('Processing file ' . $this->compilationUnit);
        $tokenType = $this->tokenizer->peek();
        while ($tokenType !== Tokenizer::T_EOF) {
            switch ($tokenType) {
                case Tokens::T_COMMENT:
                    $this->consumeToken(Tokens::T_COMMENT);
                    break;
                case Tokens::T_DOC_COMMENT:
                    $comment = $this->consumeToken(Tokens::T_DOC_COMMENT)->image;
                    $this->packageName = $this->parsePackageAnnotation($comment);
                    $this->docComment = $comment;
                    break;
                case Tokens::T_USE:
                    // Parse a use statement. This method has no return value but it
                    // creates a new entry in the symbol map.
                    $this->parseUseDeclarations();
                    break;
                case Tokens::T_NAMESPACE:
                    $this->parseNamespaceDeclaration();
                    break;
                case Tokens::T_NO_PHP:
                case Tokens::T_OPEN_TAG:
                case Tokens::T_OPEN_TAG_WITH_ECHO:
                    $this->consumeToken($tokenType);
                    $this->reset();
                    break;
                case Tokens::T_CLOSE_TAG:
                    $this->parseNonePhpCode();
                    $this->reset();
                    break;
                default:
                    if (null === $this->parseOptionalStatement()) {
                        // Consume whatever token
                        $this->consumeToken($tokenType);
                    }
                    break;
            }
            $tokenType = $this->tokenizer->peek();
        }
        $this->compilationUnit->setTokens($this->tokenStack->pop());
        $this->cache->store($this->compilationUnit->getId(), $this->compilationUnit, $hash);
        $this->tearDownEnvironment();
    }
AbstractPHPParser