コード例 #1
0
ファイル: Default.php プロジェクト: noelg/pdepend
 /**
  * Builds a new class instance or reuses a previous created class.
  *
  * Where possible you should give a qualified class name, that is prefixed
  * with the package identifier.
  *
  * <code>
  *   $builder->buildClass('php::depend::Parser');
  * </code>
  *
  * To determine the correct class, this method implements the following
  * algorithm.
  *
  * <ol>
  *   <li>Check for an exactly matching instance and reuse it.</li>
  *   <li>Check for a class instance that belongs to the default package. If
  *   such an instance exists, reuse it and replace the default package with
  *   the newly given package information.</li>
  *   <li>Check that the requested class is in the default package, if this
  *   is true, reuse the first class instance and ignore the default package.
  *   </li>
  *   <li>Create a new instance for the specified package.</li>
  * </ol>
  *
  * @param string $name The class name.
  *
  * @return PHP_Depend_Code_Class The created class object.
  */
 public function buildClass($name)
 {
     $this->checkBuilderState();
     $className = $this->extractTypeName($name);
     $packageName = $this->extractPackageName($name);
     $class = new PHP_Depend_Code_Class($className);
     $class->setSourceFile($this->defaultFile);
     $this->storeClass($className, $packageName, $class);
     return $class;
 }
コード例 #2
0
ファイル: ClassTest.php プロジェクト: rouffj/pdepend
 /**
  * Creates an abstract item instance.
  *
  * @return PHP_Depend_Code_AbstractItem
  */
 protected function createItem()
 {
     $class = new PHP_Depend_Code_Class(__CLASS__);
     $class->setSourceFile(new PHP_Depend_Code_File(__FILE__));
     $class->setCache(new PHP_Depend_Util_Cache_Driver_Memory());
     $class->setContext($this->getMock('PHP_Depend_Builder_Context'));
     return $class;
 }
コード例 #3
0
ファイル: MethodTest.php プロジェクト: rouffj/pdepend
 /**
  * Tests that build interface updates the source file information for null
  * values.
  *
  * @return void
  */
 public function testSetSourceFileInformationForNullValue()
 {
     $file = new PHP_Depend_Code_File(__FILE__);
     $class = new PHP_Depend_Code_Class(__CLASS__);
     $class->setSourceFile($file);
     $method = new PHP_Depend_Code_Method(__FUNCTION__);
     $method->setParent($class);
     self::assertSame($file, $method->getSourceFile());
 }
コード例 #4
0
ファイル: ClassTest.php プロジェクト: kingsj/core
 /**
  * testMagicWakeupSetsSourceFileOnChildMethods
  *
  * @return void
  * @group pdepend
  * @group pdepend::code
  * @group unittest
  */
 public function testMagicWakeupSetsSourceFileOnChildMethods()
 {
     $class = new PHP_Depend_Code_Class(__CLASS__);
     $method = new PHP_Depend_Code_Method(__FUNCTION__);
     $class->addMethod($method);
     $class->setContext($this->getMock('PHP_Depend_Builder_Context'));
     $file = new PHP_Depend_Code_File(__FILE__);
     $class->setSourceFile($file);
     $class->__wakeup();
     self::assertSame($file, $method->getSourceFile());
 }
コード例 #5
0
ファイル: UuidBuilderTest.php プロジェクト: KingNoosh/Teknik
 /**
  * testBuilderCreatesCaseInSensitiveMethodIdentifiers
  *
  * @return void
  */
 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));
 }
コード例 #6
0
ファイル: AbstractTest.php プロジェクト: rouffj/pdepend
 /**
  * Creates a ready to use class fixture.
  *
  * @param string $name Optional class name.
  *
  * @return PHP_Depend_Code_Class
  * @since 1.0.2
  */
 protected function createClassFixture($name = null)
 {
     $name = $name ? $name : get_class($this);
     $class = new PHP_Depend_Code_Class($name);
     $class->setSourceFile(new PHP_Depend_Code_File($GLOBALS['argv'][0]));
     $class->setCache(new PHP_Depend_Util_Cache_Driver_Memory());
     $class->setContext($this->getMock('PHP_Depend_Builder_Context'));
     return $class;
 }
コード例 #7
0
 /**
  * testBuilderCreatesExpectedIdentifierForSecondClass
  *
  * @return void
  * @covers PHP_Depend_Util_UuidBuilder
  * @group pdepend
  * @group pdepend::util
  * @group unittest
  */
 public function testBuilderCreatesExpectedIdentifierForSecondClass()
 {
     $file = new PHP_Depend_Code_File(__FILE__);
     $file->setUUID('FooBar');
     $class1 = new PHP_Depend_Code_Class(__FUNCTION__);
     $class1->setSourceFile($file);
     $class2 = new PHP_Depend_Code_Class(__CLASS__);
     $class2->setSourceFile($file);
     $builder = new PHP_Depend_Util_UuidBuilder();
     $builder->forClassOrInterface($class1);
     $this->assertRegExp('/^FooBar\\-[a-z0-9]{11}\\-00$/', $builder->forClassOrInterface($class2));
 }