/** * This method parses a function declaration. * * @return \PDepend\Source\AST\ASTFunction * @since 0.9.5 */ private function parseFunctionDeclaration() { $this->consumeComments(); // Next token must be the function identifier $functionName = $this->parseFunctionName(); $function = $this->builder->buildFunction($functionName); $function->setCompilationUnit($this->compilationUnit); $function->setId($this->idBuilder->forFunction($function)); $this->parseCallableDeclaration($function); // First check for an existing namespace if ($this->namespaceName !== null) { $packageName = $this->namespaceName; } elseif ($this->packageName !== Builder::DEFAULT_NAMESPACE) { $packageName = $this->packageName; } else { $packageName = $this->globalPackageName; } $this->builder->buildNamespace($packageName)->addFunction($function); // Store function in source file, because we need them during the file's // __wakeup() phase for function declarations within another function or // method declaration. $this->compilationUnit->addChild($function); 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)); }