Пример #1
0
 /**
  * Generates an identifier for the given method instance.
  *
  * @param PHP_Depend_Code_Method $method A method instance.
  *
  * @return string
  */
 public function forMethod(PHP_Depend_Code_Method $method)
 {
     return sprintf('%s-%s', $method->getParent()->getUUID(), $this->hash(strtolower($method->getName())));
 }
Пример #2
0
 /**
  * Tests that the {@link PHP_Depend_Code_Method::getParent()} returns as
  * default value <b>null</b> and that the package could be set and unset.
  *
  * @return void
  */
 public function testGetSetParent()
 {
     $class = new PHP_Depend_Code_Class('clazz', 0, 'clazz.php');
     $method = new PHP_Depend_Code_Method('method');
     $method->setParent($class);
     self::assertSame($class, $method->getParent());
 }
Пример #3
0
 /**
  * Adds the given method to this type.
  *
  * @param PHP_Depend_Code_Method $method A new type method.
  *
  * @return PHP_Depend_Code_Method
  */
 public function addMethod(PHP_Depend_Code_Method $method)
 {
     if ($method->getParent() !== null) {
         $method->getParent()->removeMethod($method);
     }
     // Set this as owner type
     $method->setParent($this);
     // Store method
     $this->_methods[] = $method;
     return $method;
 }
Пример #4
0
 /**
  * Returns an <b>array</b> with all aliases for the given method. If no
  * alias exists for the given method, this method will simply return the
  * an <b>array</b> with the original method.
  *
  * @param PHP_Depend_Code_Method $method The imported trait method.
  *
  * @return PHP_Depend_Code_Method[]
  */
 private function getAliasesFor(PHP_Depend_Code_Method $method)
 {
     $name = strtolower($method->getName());
     $newNames = array();
     foreach ($this->getAliases() as $alias) {
         $name2 = strtolower($alias->getImage());
         if ($name2 !== $name) {
             continue;
         }
         $modifier = $method->getModifiers();
         if (-1 < $alias->getNewModifier()) {
             $modifier &= ~(PHP_Depend_ConstantsI::IS_PUBLIC | PHP_Depend_ConstantsI::IS_PROTECTED | PHP_Depend_ConstantsI::IS_PRIVATE);
             $modifier |= $alias->getNewModifier();
         }
         $newName = $method->getName();
         if ($alias->getNewName()) {
             $newName = $alias->getNewName();
         }
         if (0 === count($alias->getChildren())) {
             $newMethod = clone $method;
             $newMethod->setName($newName);
             $newMethod->setModifiers($modifier);
             $newNames[] = $newMethod;
             continue;
         }
         if ($alias->getChild(0)->getType() !== $method->getParent()) {
             continue;
         }
         $newMethod = clone $method;
         $newMethod->setName($newName);
         $newMethod->setModifiers($modifier);
         $newNames[] = $newMethod;
     }
     if (count($newNames) > 0) {
         return $newNames;
     }
     return array($method);
 }
Пример #5
0
 /**
  * Tests that the {@link PHP_Depend_Code_Class::addMethod()} method adds a
  * method to the internal list and sets the context class as parent.
  *
  * @return void
  * @covers PHP_Depend_Code_AbstractClassOrInterface
  * @covers PHP_Depend_Code_Class
  * @group pdepend
  * @group pdepend::code
  * @group unittest
  */
 public function testAddNewMethod()
 {
     $class = new PHP_Depend_Code_Class('clazz', 0);
     $method = new PHP_Depend_Code_Method('method', 0);
     $this->assertNull($method->getParent());
     $class->addMethod($method);
     $this->assertSame($class, $method->getParent());
     $this->assertEquals(1, $class->getMethods()->count());
 }