예제 #1
0
파일: FileTest.php 프로젝트: kingsj/core
 /**
  * testGetUuidReturnsInjectedUuidValue
  *
  * @return void
  * @group pdepend
  * @group pdepend::code
  * @group unittest
  */
 public function testGetUuidReturnsInjectedUuidValue()
 {
     $file = new PHP_Depend_Code_File(__FILE__);
     $file->setUUID(__FUNCTION__);
     self::assertEquals(__FUNCTION__, $file->getUuid());
 }
예제 #2
0
 /**
  * Visits a file node.
  *
  * @param PHP_Depend_Code_File $file The current file node.
  *
  * @return void
  * @see PHP_Depend_Visitor_AbstractVisitor::visitFile()
  */
 public function visitFile(PHP_Depend_Code_File $file)
 {
     // Skip for dummy files
     if ($file->getFileName() === null) {
         return;
     }
     // Check for initial file
     $uuid = $file->getUuid();
     if (isset($this->metrics[$uuid])) {
         return;
     }
     $this->fireStartFile($file);
     if ($this->restoreFromCache($file)) {
         $this->updateProjectMetrics($uuid);
         return $this->fireEndFile($file);
     }
     list($cloc, $eloc, $lloc) = $this->linesOfCode($file->getTokens());
     $loc = $file->getEndLine();
     $ncloc = $loc - $cloc;
     $this->metrics[$uuid] = array(self::M_LINES_OF_CODE => $loc, self::M_COMMENT_LINES_OF_CODE => $cloc, self::M_EXECUTABLE_LINES_OF_CODE => $eloc, self::M_LOGICAL_LINES_OF_CODE => $lloc, self::M_NON_COMMENT_LINES_OF_CODE => $ncloc);
     $this->updateProjectMetrics($uuid);
     $this->fireEndFile($file);
 }
예제 #3
0
 /**
  * Parses the contents of the tokenizer and generates a node tree based on
  * the found tokens.
  *
  * @return void
  */
 public function parse()
 {
     $this->sourceFile = $this->tokenizer->getSourceFile();
     $this->sourceFile->setCache($this->cache)->setUuid($this->uuidBuilder->forFile($this->sourceFile));
     $hash = md5_file($this->sourceFile->getFileName());
     if ($this->cache->restore($this->sourceFile->getUuid(), $hash)) {
         return;
     }
     $this->cache->remove($this->sourceFile->getUuid());
     $this->setUpEnvironment();
     $this->tokenStack->push();
     PHP_Depend_Util_Log::debug('Processing file ' . $this->sourceFile);
     $tokenType = $this->tokenizer->peek();
     while ($tokenType !== self::T_EOF) {
         switch ($tokenType) {
             case self::T_COMMENT:
                 $this->consumeToken(self::T_COMMENT);
                 break;
             case self::T_DOC_COMMENT:
                 $comment = $this->consumeToken(self::T_DOC_COMMENT)->image;
                 $this->packageName = $this->parsePackageAnnotation($comment);
                 $this->docComment = $comment;
                 break;
             case self::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 self::T_NAMESPACE:
                 $this->parseNamespaceDeclaration();
                 break;
             case self::T_NO_PHP:
             case self::T_OPEN_TAG:
             case self::T_OPEN_TAG_WITH_ECHO:
                 $this->consumeToken($tokenType);
                 $this->reset();
                 break;
             case self::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->sourceFile->setTokens($this->tokenStack->pop());
     $this->cache->store($this->sourceFile->getUuid(), $this->sourceFile, $hash);
     $this->tearDownEnvironment();
 }