/** * 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(); $interface = new PHP_Depend_Code_Interface($this->extractTypeName($name)); $interface->setCache($this->cache)->setContext($this->context)->setSourceFile($this->defaultFile); 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; }
/** * 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; }
/** * testGetEndLineReturnsEndLineOfLastToken * * @return void * @group pdepend * @group pdepend::code * @group unittest */ public function testGetEndLineReturnsEndLineOfLastToken() { $cache = $this->getMock('PHP_Depend_Util_Cache_Driver'); $cache->expects($this->once())->method('type')->will($this->returnValue($cache)); $interface = new PHP_Depend_Code_Interface(__CLASS__); $interface->setCache($cache)->setTokens(array(new PHP_Depend_Token(1, 'a', 23, 42, 0, 0), new PHP_Depend_Token(2, 'b', 17, 32, 0, 0))); self::assertEquals(32, $interface->getEndLine()); }