Пример #1
0
 /**
  * Visits a method node.
  *
  * @param PHP_Depend_Code_Class $method The method class node.
  *
  * @return void
  * @see PHP_Depend_VisitorI::visitMethod()
  */
 public function visitMethod(PHP_Depend_Code_Method $method)
 {
     $this->visits[] = $method->getName();
     parent::visitMethod($method);
 }
Пример #2
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())));
 }
Пример #3
0
 /**
  * Visits a method node.
  *
  * @param PHP_Depend_Code_Class $method The method class node.
  *
  * @return void
  * @see PHP_Depend_VisitorI::visitMethod()
  */
 public function visitMethod(PHP_Depend_Code_Method $method)
 {
     $classXml = end($this->_xmlStack);
     $document = $classXml->ownerDocument;
     $methodXml = $document->createElement('method');
     $methodXml->setAttribute('name', $method->getName());
     $this->_appendMetrics($methodXml, $method);
     $classXml->appendChild($methodXml);
 }
Пример #4
0
 /**
  * Visits the given method.
  *
  * @param PHP_Depend_Code_Method $method The context method.
  *
  * @return void
  */
 public function visitMethod(PHP_Depend_Code_Method $method)
 {
     if ($method->isAbstract() === false) {
         $this->_visitCallable($method);
     }
 }
Пример #5
0
 /**
  * Visits a method node.
  *
  * @param PHP_Depend_Code_Method $node The method class node.
  *
  * @return void
  * @see PHP_Depend_VisitorI::visitMethod()
  */
 public function visitMethod(PHP_Depend_Code_Method $node)
 {
     if ($node->getSourceFile()->getFileName() === null) {
         return;
     }
     $this->_apply(new PHP_PMD_Node_Method($node));
 }
Пример #6
0
 /**
  * Builds a new method instance.
  *
  * @param string $name The method name.
  *
  * @return PHP_Depend_Code_Method The created class method object.
  */
 public function buildMethod($name)
 {
     $this->checkBuilderState();
     // Debug method creation
     PHP_Depend_Util_Log::debug("Creating: PHP_Depend_Code_Method({$name})");
     // Create a new method instance
     $method = new PHP_Depend_Code_Method($name);
     $method->setCache($this->cache);
     return $method;
 }
Пример #7
0
 /**
  * Creates an abstract item instance.
  *
  * @return PHP_Depend_Code_AbstractItem
  */
 protected function createItem()
 {
     $method = new PHP_Depend_Code_Method('method');
     $method->setSourceFile(new PHP_Depend_Code_File(__FILE__));
     return $method;
 }
Пример #8
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);
 }
Пример #9
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)
 {
     $method->setParent($this);
     $this->methods[] = $method;
     return $method;
 }
Пример #10
0
 /**
  * Tests the behavior of {@link PHP_Depend_Code_Method::findChildrenOfType()}.
  *
  * @return void
  * @group pdepend
  * @group pdepend::code
  * @group unittest
  */
 public function testFindChildrenOfTypeReturnsExpectedResult()
 {
     $node1 = $this->getMock('PHP_Depend_Code_ASTNodeI', array(), array(), 'PHP_Depend_Code_ASTNodeI_' . md5(microtime()));
     $node1->expects($this->once())->method('findChildrenOfType')->will($this->returnValue(array()));
     $node2 = $this->getMock('PHP_Depend_Code_ASTNodeI', array(), array(), 'PHP_Depend_Code_ASTNodeI_' . md5(microtime()));
     $node2->expects($this->once())->method('findChildrenOfType')->will($this->returnValue(array()));
     $method = new PHP_Depend_Code_Method('Method');
     $method->addChild($node1);
     $method->addChild($node2);
     $children = $method->findChildrenOfType(get_class($node2));
     self::assertSame(array($node2), $children);
 }
Пример #11
0
 /**
  * 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));
 }
Пример #12
0
 /**
  * Creates a ready to use method fixture.
  *
  * @param string $name Optional method name.
  *
  * @return PHP_Depend_Code_Method
  * @since 1.0.2
  */
 protected function createMethodFixture($name = null)
 {
     $name = $name ? $name : get_class($this);
     $method = new PHP_Depend_Code_Method($name);
     $method->setCache(new PHP_Depend_Util_Cache_Driver_Memory());
     $method->addChild(new PHP_Depend_Code_ASTFormalParameters());
     return $method;
 }
Пример #13
0
 /**
  * testBuilderCreatesExpectedIdentifierForMethod
  *
  * @return void
  * @covers PHP_Depend_Util_UuidBuilder
  * @group pdepend
  * @group pdepend::util
  * @group unittest
  */
 public function testBuilderCreatesExpectedIdentifierForMethod()
 {
     $class = new PHP_Depend_Code_Class(__CLASS__);
     $class->setUUID('FooBar');
     $method = new PHP_Depend_Code_Method(__FUNCTION__);
     $method->setParent($class);
     $builder = new PHP_Depend_Util_UuidBuilder();
     $this->assertRegExp('/^FooBar\\-[a-z0-9]{11}$/', $builder->forMethod($method));
 }
Пример #14
0
 /**
  * Constructs a new exception instance.
  *
  * @param PHP_Depend_Code_Method       $method The method that could not be
  *        applied to the given <b>$type</b>.
  * @param PHP_Depend_Code_AbstractType $type   The class or trait that cannot
  *        resolve the imported methods.
  */
 public function __construct(PHP_Depend_Code_Method $method, PHP_Depend_Code_AbstractType $type)
 {
     parent::__construct(sprintf('Trait method %s has not been applied, because there are ' . 'collisions with other trait methods on %s\\%s.', $method->getName(), preg_replace('(\\W+)', '\\', $type->getPackage()->getName()), $type->getName()));
 }
Пример #15
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;
 }
Пример #16
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());
 }