Exemple #1
0
 /**
  * Parses the contents of the tokenizer and generates a node tree based on
  * the found tokens.
  *
  * @return void
  */
 public function parse()
 {
     $this->setUpEnvironment();
     // Get currently parsed source file
     $this->_sourceFile = $this->_tokenizer->getSourceFile();
     $this->_sourceFile->setUUID($this->_uuidBuilder->forFile($this->_sourceFile));
     // Debug currently parsed source file.
     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_INTERFACE:
                 $package = $this->_builder->buildPackage($this->_getNamespaceOrPackageName());
                 $package->addType($this->_parseInterfaceDeclaration());
                 break;
             case self::T_CLASS:
             case self::T_FINAL:
             case self::T_ABSTRACT:
                 $package = $this->_builder->buildPackage($this->_getNamespaceOrPackageName());
                 $package->addType($this->_parseClassDeclaration());
                 break;
             case self::T_FUNCTION:
                 $this->_parseFunctionOrClosureDeclaration();
                 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;
             default:
                 // Consume whatever token
                 $this->_consumeToken($tokenType);
                 $this->reset();
                 break;
         }
         $tokenType = $this->_tokenizer->peek();
     }
     $this->tearDownEnvironment();
 }
Exemple #2
0
 /**
  * testSetTokensDelegatesCallToCacheStoreWithFileUuid
  *
  * @return void
  * @group pdepend
  * @group pdepend::code
  * @group unittest
  */
 public function testSetTokensDelegatesCallToCacheStoreWithFileUuid()
 {
     $cache = $this->getMock('PHP_Depend_Util_Cache_Driver');
     $cache->expects($this->once())->method('type')->with(self::equalTo('tokens'))->will($this->returnValue($cache));
     $cache->expects($this->once())->method('store')->with(self::equalTo(__FUNCTION__), self::equalTo(array(1, 2, 3)));
     $file = new PHP_Depend_Code_File(null);
     $file->setCache($cache);
     $file->setUUID(__FUNCTION__);
     $file->setTokens(array(1, 2, 3));
 }
Exemple #3
0
 /**
  * testBuilderCreatesCaseInSensitiveMethodIdentifiers
  *
  * @return void
  * @covers PHP_Depend_Util_UuidBuilder
  * @group pdepend
  * @group pdepend::util
  * @group unittest
  */
 public function testBuilderCreatesCaseInSensitiveMethodIdentifiers()
 {
     $file = new PHP_Depend_Code_File(__FILE__);
     $file->setUUID(__FUNCTION__);
     $class = new PHP_Depend_Code_Class(__FUNCTION__);
     $class->setSourceFile($file);
     $method0 = new PHP_Depend_Code_Method(__FUNCTION__);
     $method0->setParent($class);
     $method1 = new PHP_Depend_Code_Method(strtolower(__FUNCTION__));
     $method1->setParent($class);
     $builder0 = new PHP_Depend_Util_UuidBuilder();
     $builder1 = new PHP_Depend_Util_UuidBuilder();
     self::assertEquals($builder0->forMethod($method0), $builder1->forMethod($method1));
 }
 /**
  * testBuilderCreatesExpectedIdentifierForSecondFunction
  *
  * @return void
  * @covers PHP_Depend_Util_UuidBuilder
  * @group pdepend
  * @group pdepend::util
  * @group unittest
  */
 public function testBuilderCreatesExpectedIdentifierForSecondFunction()
 {
     $file = new PHP_Depend_Code_File(__FILE__);
     $file->setUUID('FooBar');
     $function1 = new PHP_Depend_Code_Function(__FUNCTION__);
     $function1->setSourceFile($file);
     $function2 = new PHP_Depend_Code_Function(__CLASS__);
     $function2->setSourceFile($file);
     $builder = new PHP_Depend_Util_UuidBuilder();
     $builder->forFunction($function1);
     $this->assertRegExp('/^FooBar\\-[a-z0-9]{11}\\-00$/', $builder->forFunction($function2));
 }
Exemple #5
0
 /**
  * testAnalyzerIgnoresFilesWithoutFileName
  *
  * @return void
  */
 public function testAnalyzerIgnoresFilesWithoutFileName()
 {
     $file = new PHP_Depend_Code_File(null);
     $file->setUUID(42);
     $analyzer = $this->_createAnalyzer();
     $analyzer->visitFile($file);
     $metrics = $analyzer->getNodeMetrics($file);
     self::assertEquals(array(), $metrics);
 }