Esempio n. 1
0
 /**
  * @param  MethodReflection $reflectionMethod
  * @return MethodGenerator
  */
 public static function fromReflection(MethodReflection $reflectionMethod)
 {
     $method = new static();
     $declaringClass = $reflectionMethod->getDeclaringClass();
     $method->setSourceContent($reflectionMethod->getContents(false));
     $method->setSourceDirty(false);
     if ($reflectionMethod->getDocComment() != '') {
         $method->setDocBlock(DocBlockGenerator::fromReflection($reflectionMethod->getDocBlock()));
     }
     $method->setFinal($reflectionMethod->isFinal());
     if ($reflectionMethod->isPrivate()) {
         $method->setVisibility(self::VISIBILITY_PRIVATE);
     } elseif ($reflectionMethod->isProtected()) {
         $method->setVisibility(self::VISIBILITY_PROTECTED);
     } else {
         $method->setVisibility(self::VISIBILITY_PUBLIC);
     }
     $method->setInterface($declaringClass->isInterface());
     $method->setStatic($reflectionMethod->isStatic());
     $method->setName($reflectionMethod->getName());
     foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
         $method->setParameter(ParameterGenerator::fromReflection($reflectionParameter));
     }
     $method->setBody(static::clearBodyIndention($reflectionMethod->getBody()));
     return $method;
 }
Esempio n. 2
0
 public function testGetBodyReturnsCorrectBody()
 {
     $body = '        //we need a multi-line method body.
     $assigned = 1;
     $alsoAssigined = 2;
     return \'mixedValue\';';
     $reflectionMethod = new MethodReflection('ZendTest\\Code\\Reflection\\TestAsset\\TestSampleClass6', 'doSomething');
     $this->assertEquals($body, $reflectionMethod->getBody());
 }
Esempio n. 3
0
 public function testGetContentsReturnsEmptyContentsOnEvaldCode()
 {
     $className = uniqid('MethodReflectionTestGenerated');
     eval('name' . 'space ' . __NAMESPACE__ . '; cla' . 'ss ' . $className . '{fun' . 'ction foo(){}}');
     $reflectionMethod = new MethodReflection(__NAMESPACE__ . '\\' . $className, 'foo');
     $this->assertSame('', $reflectionMethod->getContents());
     $this->assertSame('', $reflectionMethod->getBody());
 }