Example #1
0
 /**
  * The magic sleep method is called by the PHP runtime environment before an
  * instance of this class gets serialized. It returns an array with the
  * names of all those properties that should be cached for this class or
  * interface instance.
  *
  * @return array
  */
 public function __sleep()
 {
     if (is_array($this->methods)) {
         $this->cache->type('methods')->store($this->id, $this->methods);
         $this->methods = null;
     }
     return array('cache', 'context', 'docComment', 'endLine', 'modifiers', 'name', 'nodes', 'namespaceName', 'startLine', 'userDefined', 'id');
 }
Example #2
0
 /**
  * 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();
 }
Example #3
0
 /**
  * Sets the tokens for this file.
  *
  * @param array(array) $tokens The generated tokens.
  *
  * @return void
  */
 public function setTokens(array $tokens)
 {
     $this->cache->type('tokens')->store($this->getId(), $tokens);
 }
Example #4
0
 /**
  * Unloads the metrics cache and stores the current set of metrics in the
  * cache.
  *
  * @return void
  */
 protected function unloadCache()
 {
     $this->cache->type('metrics')->store(get_class($this), $this->metrics);
     $this->metricsCached = array();
 }
 /**
  * Sets the tokens found in the function body.
  *
  * @param \PDepend\Source\Tokenizer\Token[] $tokens The body tokens.
  *
  * @return void
  */
 public function setTokens(array $tokens)
 {
     $this->startLine = reset($tokens)->startLine;
     $this->endLine = end($tokens)->endLine;
     $this->cache->type('tokens')->store($this->id, $tokens);
 }