Ejemplo n.º 1
0
 /**
  * Builds a new function instance.
  *
  * @param string $name The function name.
  *
  * @return PHP_Depend_Code_Function The function instance.
  */
 public function buildFunction($name)
 {
     $this->checkBuilderState();
     // Debug function creation
     PHP_Depend_Util_Log::debug('Creating: PHP_Depend_Code_Function(' . $name . ')');
     // Create new function
     $function = new PHP_Depend_Code_Function($name);
     $function->setSourceFile($this->defaultFile);
     return $function;
 }
Ejemplo n.º 2
0
Archivo: Xml.php Proyecto: kingsj/core
 /**
  * Visits a function node.
  *
  * @param PHP_Depend_Code_Function $function The current function node.
  *
  * @return void
  * @see PHP_Depend_VisitorI::visitFunction()
  */
 public function visitFunction(PHP_Depend_Code_Function $function)
 {
     // First visit function file
     $function->getSourceFile()->accept($this);
     $fileXml = end($this->_xmlStack);
     $document = $fileXml->ownerDocument;
     $functionXml = $document->createElement('function');
     $functionXml->setAttribute('name', $function->getName());
     $this->_appendMetrics($functionXml, $function);
     $fileXml->appendChild($functionXml);
     // Update file element @functions count
     $fileXml->setAttribute('functions', 1 + $fileXml->getAttribute('functions'));
     // Remove xml file element
     array_pop($this->_xmlStack);
 }
Ejemplo n.º 3
0
 /**
  * Visits a function node.
  *
  * @param PHP_Depend_Code_Function $function The current function node.
  *
  * @return void
  * @see PHP_Depend_VisitorI::visitFunction()
  */
 public function visitFunction(PHP_Depend_Code_Function $function)
 {
     $this->visits[] = $function->getName();
     parent::visitFunction($function);
 }
Ejemplo n.º 4
0
 /**
  * Visits a function node.
  *
  * @param PHP_Depend_Code_Function $function The current function node.
  *
  * @return void
  * @see PHP_Depend_VisitorI::visitFunction()
  */
 public function visitFunction(PHP_Depend_Code_Function $function)
 {
     $xml = end($this->_xmlStack);
     $doc = $xml->ownerDocument;
     $functionXml = $doc->createElement('function');
     $functionXml->setAttribute('name', $function->getName());
     $this->writeNodeMetrics($functionXml, $function);
     $this->writeFileReference($functionXml, $function->getSourceFile());
     $xml->appendChild($functionXml);
 }
Ejemplo n.º 5
0
 /**
  * Visits a function node.
  *
  * @param PHP_Depend_Code_Function $node The current function node.
  *
  * @return void
  * @see PHP_Depend_VisitorI::visitFunction()
  */
 public function visitFunction(PHP_Depend_Code_Function $node)
 {
     if ($node->getSourceFile()->getFileName() === null) {
         return;
     }
     $this->_apply(new PHP_PMD_Node_Function($node));
 }
Ejemplo n.º 6
0
 /**
  * Builds a new function instance.
  *
  * @param string $name The function name.
  *
  * @return PHP_Depend_Code_Function The function instance.
  */
 public function buildFunction($name)
 {
     $this->checkBuilderState();
     // Debug function creation
     PHP_Depend_Util_Log::debug("Creating: PHP_Depend_Code_Function({$name})");
     // Create new function
     $function = new PHP_Depend_Code_Function($name);
     $function->setCache($this->cache)->setContext($this->context)->setSourceFile($this->defaultFile);
     return $function;
 }
Ejemplo n.º 7
0
 /**
  * testRestoreFunctionAddsFunctionToPackage
  *
  * @return void
  */
 public function testRestoreFunctionAddsFunctionToPackage()
 {
     $builder = $this->createBuilder();
     $package = $builder->buildPackage(__CLASS__);
     $function = new PHP_Depend_Code_Function(__FUNCTION__);
     $function->setPackage($package);
     $builder->restoreFunction($function);
     self::assertEquals(1, count($package->getFunctions()));
 }
Ejemplo n.º 8
0
 /**
  * Tests the visitor accept method.
  *
  * @return void
  */
 public function testVisitorAccept()
 {
     $function = new PHP_Depend_Code_Function('func');
     $visitor = new PHP_Depend_Visitor_TestNodeVisitor();
     $function->accept($visitor);
     $this->assertSame($function, $visitor->function);
 }
Ejemplo n.º 9
0
 /**
  * testBuilderCreatesExpectedIdentifierForSecondFunction
  *
  * @return void
  */
 public function testBuilderCreatesExpectedIdentifierForSecondFunction()
 {
     $file = new PHP_Depend_Code_File(__FILE__);
     $file->setUuid('FooBar');
     $function1 = new PHP_Depend_Code_Function(__FUNCTION__);
     $function1->setSourceFile($file);
     $function2 = new PHP_Depend_Code_Function(__CLASS__);
     $function2->setSourceFile($file);
     $builder = new PHP_Depend_Util_UuidBuilder();
     $builder->forFunction($function1);
     $this->assertRegExp('/^FooBar\\-[a-z0-9]{11}\\-00$/', $builder->forFunction($function2));
 }
Ejemplo n.º 10
0
 /**
  * Creates an abstract item instance.
  *
  * @return PHP_Depend_Code_AbstractItem
  */
 protected function createItem()
 {
     $function = new PHP_Depend_Code_Function(__FUNCTION__);
     $function->setContext($this->getMock('PHP_Depend_Builder_Context'));
     return $function;
 }
Ejemplo n.º 11
0
 /**
  * Creates a ready to use function fixture.
  *
  * @param string $name Optional function name.
  *
  * @return PHP_Depend_Code_Function
  * @since 1.0.2
  */
 protected function createFunctionFixture($name = null)
 {
     $name = $name ? $name : get_class($this);
     $function = new PHP_Depend_Code_Function($name);
     $function->setSourceFile(new PHP_Depend_Code_File($GLOBALS['argv'][0]));
     $function->setCache(new PHP_Depend_Util_Cache_Driver_Memory());
     $function->addChild(new PHP_Depend_Code_ASTFormalParameters());
     return $function;
 }
Ejemplo n.º 12
0
 /**
  * Adds the given function to this package and returns the input instance.
  *
  * @param PHP_Depend_Code_Function $function The new package function.
  *
  * @return PHP_Depend_Code_Function
  */
 public function addFunction(PHP_Depend_Code_Function $function)
 {
     if ($function->getPackage() !== null) {
         $function->getPackage()->removeFunction($function);
     }
     // Set this as function package
     $function->setPackage($this);
     // Append function to internal list
     $this->functions[] = $function;
     return $function;
 }