/** * @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; }
/** * Retrieves the visibility for the given method reflection * * @param MethodReflection $reflectionMethod * * @return string */ private static function extractVisibility(MethodReflection $reflectionMethod) { if ($reflectionMethod->isPrivate()) { return static::VISIBILITY_PRIVATE; } if ($reflectionMethod->isProtected()) { return static::VISIBILITY_PROTECTED; } return static::VISIBILITY_PUBLIC; }