Beispiel #1
0
 /**
  * This method parses a function declaration.
  *
  * @return PHP_Depend_Code_Function
  * @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->setSourceFile($this->_sourceFile);
     $function->setUUID($this->_uuidBuilder->forFunction($function));
     $this->_parseCallableDeclaration($function);
     // First check for an existing namespace
     if ($this->_namespaceName !== null) {
         $packageName = $this->_namespaceName;
     } else {
         if ($this->_packageName !== self::DEFAULT_PACKAGE) {
             $packageName = $this->_packageName;
         } else {
             $packageName = $this->_globalPackageName;
         }
     }
     $this->builder->buildPackage($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->_sourceFile->addChild($function);
     return $function;
 }
Beispiel #2
0
 /**
  * This method parses a simple function or a PHP 5.3 lambda function or
  * closure.
  *
  * @return PHP_Depend_Code_AbstractCallable
  * @since 0.9.5
  */
 private function _parseFunctionOrClosureDeclaration()
 {
     $this->_tokenStack->push();
     $this->_consumeToken(self::T_FUNCTION);
     $this->_consumeComments();
     $returnReference = $this->_parseOptionalReturnbyReference();
     if ($this->_isNextTokenFormalParameterList()) {
         $callable = $this->_parseClosureDeclaration();
         $callable->setSourceFile($this->_sourceFile);
     } else {
         $callable = $this->_parseFunctionDeclaration();
         $callable->setSourceFile($this->_sourceFile);
         $callable->setUUID($this->_uuidBuilder->forFunction($callable));
     }
     $callable->setDocComment($this->_docComment);
     $callable->setTokens($this->_tokenStack->pop());
     $this->_prepareCallable($callable);
     if ($returnReference) {
         $callable->setReturnsReference();
     }
     $this->reset();
     return $callable;
 }
Beispiel #3
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));
 }
 /**
  * testBuilderCreatesExpectedIdentifierForSecondFunction
  *
  * @return void
  * @covers PHP_Depend_Util_UuidBuilder
  * @group pdepend
  * @group pdepend::util
  * @group unittest
  */
 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));
 }