예제 #1
0
 /**
  * Builds a new function instance.
  *
  * @param  string $name The function name.
  * @return ASTFunction
  */
 public function buildFunction($name)
 {
     $this->checkBuilderState();
     // Debug function creation
     Log::debug("Creating: \\PDepend\\Source\\AST\\ASTFunction({$name})");
     // Create new function
     $function = new ASTFunction($name);
     $function->setCache($this->cache)->setContext($this->context)->setCompilationUnit($this->defaultCompilationUnit);
     return $function;
 }
예제 #2
0
 /**
  * Adds the given function to this namespace and returns the input instance.
  *
  * @param  \PDepend\Source\AST\ASTFunction $function
  * @return \PDepend\Source\AST\ASTFunction
  */
 public function addFunction(ASTFunction $function)
 {
     if ($function->getNamespace() !== null) {
         $function->getNamespace()->removeFunction($function);
     }
     $function->setNamespace($this);
     // Append function to internal list
     $this->functions[$function->getId()] = $function;
     return $function;
 }
 /**
  * testRestoreFunctionAddsFunctionToPackage
  *
  * @return void
  */
 public function testRestoreFunctionAddsFunctionToPackage()
 {
     $builder = $this->createBuilder();
     $namespace = $builder->buildNamespace(__CLASS__);
     $function = new ASTFunction(__FUNCTION__);
     $function->setNamespace($namespace);
     $builder->restoreFunction($function);
     $this->assertEquals(1, count($namespace->getFunctions()));
 }
 /**
  * Visits a function node.
  *
  * @param \PDepend\Source\AST\ASTFunction $function
  * @return void
  */
 public function visitFunction(ASTFunction $function)
 {
     $this->visits[] = $function->getName();
     parent::visitFunction($function);
 }
예제 #5
0
    /**
     * Visits a function node.
     *
     * @param \PDepend\Source\AST\ASTFunction $function
     * @return void
     */
    public function visitFunction(ASTFunction $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->getCompilationUnit());

        $xml->appendChild($functionXml);
    }
예제 #6
0
파일: Parser.php 프로젝트: flavius/phpmd
 /**
  * Visits a function node.
  *
  * @param \PDepend\Source\AST\ASTFunction $node
  * @return void
  */
 public function visitFunction(ASTFunction $node)
 {
     if ($node->getCompilationUnit()->getFileName() === null) {
         return;
     }
     $this->apply(new FunctionNode($node));
 }
 /**
  * Creates an abstract item instance.
  *
  * @return \PDepend\Source\AST\AbstractASTArtifact
  */
 protected function createItem()
 {
     $function = new ASTFunction(__FUNCTION__);
     $function->setCompilationUnit(new ASTCompilationUnit(__FILE__));
     $function->setContext($this->getMock('PDepend\\Source\\Builder\\BuilderContext'));
     return $function;
 }
 /**
  * testBuilderCreatesExpectedIdentifierForSecondFunction
  *
  * @return void
  */
 public function testBuilderCreatesExpectedIdentifierForSecondFunction()
 {
     $compilationUnit = new ASTCompilationUnit(__FILE__);
     $compilationUnit->setId('FooBar');
     $function1 = new ASTFunction(__FUNCTION__);
     $function1->setCompilationUnit($compilationUnit);
     $function2 = new ASTFunction(__CLASS__);
     $function2->setCompilationUnit($compilationUnit);
     $builder = new IdBuilder();
     $builder->forFunction($function1);
     $this->assertRegExp('/^FooBar\\-[a-z0-9]{11}\\-00$/', $builder->forFunction($function2));
 }
 /**
  * Creates a ready to use function fixture.
  *
  * @param string $name Optional function name.
  * @return \PDepend\Source\AST\ASTFunction
  * @since 1.0.2
  */
 protected function createFunctionFixture($name = null)
 {
     $name = $name ? $name : get_class($this);
     $function = new ASTFunction($name);
     $function->setCompilationUnit(new ASTCompilationUnit($GLOBALS['argv'][0]));
     $function->setCache(new MemoryCacheDriver());
     $function->addChild(new ASTFormalParameters());
     return $function;
 }