/** * Builds a new new interface instance. * * If there is an existing class instance for the given name, this method * checks if this class is part of the default namespace. If this is the * case this method will update all references to the new interface and it * removes the class instance. Otherwise it creates new interface instance. * * Where possible you should give a qualified interface name, that is * prefixed with the package identifier. * * <code> * $builder->buildInterface('php::depend::Parser'); * </code> * * To determine the correct interface, this method implements the following * algorithm. * * <ol> * <li>Check for an exactly matching instance and reuse it.</li> * <li>Check for a interface 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 interface is in the default package, if * this is true, reuse the first interface instance and ignore the default * package. * </li> * <li>Create a new instance for the specified package.</li> * </ol> * * @param string $name The interface name. * * @return PHP_Depend_Code_Interface The created interface object. */ public function buildInterface($name) { $this->checkBuilderState(); $interfaceName = $this->extractTypeName($name); $packageName = $this->extractPackageName($name); $interface = new PHP_Depend_Code_Interface($interfaceName); $interface->setSourceFile($this->defaultFile); $this->storeInterface($interfaceName, $packageName, $interface); return $interface; }
/** * Creates an abstract item instance. * * @return PHP_Depend_Code_Interface */ protected function createItem() { $interface = new PHP_Depend_Code_Interface(__CLASS__); $interface->setSourceFile(new PHP_Depend_Code_File(__FILE__)); $interface->setCache(new PHP_Depend_Util_Cache_Driver_Memory()); $interface->setContext($this->getMock('PHP_Depend_Builder_Context')); return $interface; }
/** * Creates a ready to use interface fixture. * * @param string $name Optional interface name. * * @return PHP_Depend_Code_Interface * @since 1.0.2 */ protected function createInterfaceFixture($name = null) { $name = $name ? $name : get_class($this); $interface = new PHP_Depend_Code_Interface($name); $interface->setSourceFile(new PHP_Depend_Code_File($GLOBALS['argv'][0])); $interface->setCache(new PHP_Depend_Util_Cache_Driver_Memory()); return $interface; }
/** * testBuilderCreatesCaseInSensitiveInterfaceIdentifiers * * @return void */ public function testBuilderCreatesCaseInSensitiveInterfaceIdentifiers() { $file = new PHP_Depend_Code_File(__FILE__); $file->setUuid(__FUNCTION__); $interface0 = new PHP_Depend_Code_Interface(__FUNCTION__); $interface0->setSourceFile($file); $interface1 = new PHP_Depend_Code_Interface(strtolower(__FUNCTION__)); $interface1->setSourceFile($file); $builder0 = new PHP_Depend_Util_UuidBuilder(); $builder1 = new PHP_Depend_Util_UuidBuilder(); self::assertEquals($builder0->forClassOrInterface($interface0), $builder1->forClassOrInterface($interface1)); }
/** * testMagicWakeupSetsSourceFileOnChildMethods * * @return void * @group pdepend * @group pdepend::code * @group unittest */ public function testMagicWakeupSetsSourceFileOnChildMethods() { $interface = new PHP_Depend_Code_Interface(__CLASS__); $method = new PHP_Depend_Code_Method(__FUNCTION__); $interface->addMethod($method); $file = new PHP_Depend_Code_File(__FILE__); $interface->setSourceFile($file); $interface->setContext($this->getMock('PHP_Depend_Builder_Context')); $interface->__wakeup(); self::assertSame($file, $method->getSourceFile()); }