/** * Parses the contents of the tokenizer and generates a node tree based on * the found tokens. * * @return void */ public function parse() { $this->compilationUnit = $this->tokenizer->getSourceFile(); $this->compilationUnit->setCache($this->cache)->setId($this->idBuilder->forFile($this->compilationUnit)); $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(); }
/** * Assign CLI arguments to current runner instance * * @return bool */ protected function assignArguments() { if ($this->source) { $this->runner->setSourceArguments($this->source); } // Check for suffix option if (isset($this->options['--suffix'])) { // Get file extensions $extensions = explode(',', $this->options['--suffix']); // Set allowed file extensions $this->runner->setFileExtensions($extensions); unset($this->options['--suffix']); } // Check for ignore option if (isset($this->options['--ignore'])) { // Get exclude directories $directories = explode(',', $this->options['--ignore']); // Set exclude directories $this->runner->setExcludeDirectories($directories); unset($this->options['--ignore']); } // Check for exclude namespace option if (isset($this->options['--exclude'])) { // Get exclude directories $namespaces = explode(',', $this->options['--exclude']); // Set exclude namespace $this->runner->setExcludeNamespaces($namespaces); unset($this->options['--exclude']); } // Check for the bad documentation option if (isset($this->options['--bad-documentation'])) { echo "Option --bad-documentation is ambiguous.", PHP_EOL; unset($this->options['--bad-documentation']); } $configuration = $this->application->getConfiguration(); // Store in config registry ConfigurationInstance::set($configuration); if (isset($this->options['--debug'])) { unset($this->options['--debug']); Log::setSeverity(Log::DEBUG); } }
/** * Creates a {@link \PDepend\Source\AST\ASTNode} instance. * * @param string $className Local name of the ast node class. * @param string $image Optional image for the created ast node. * * @return \PDepend\Source\AST\ASTNode * @since 0.9.12 */ private function buildAstNodeInstance($className, $image = null) { $className = "\\PDepend\\Source\\AST\\{$className}"; Log::debug("Creating: {$className}({$image})"); return new $className($image); }
/** * Removes the given cache file. * * @param \SplFileInfo $file * @return void */ private function garbageCollectFile(\SplFileInfo $file) { Log::debug("Removing file '{$file->getPathname()}' from cache."); @unlink($file->getPathname()); }