Creates a method from Reflection Method.

@param \ReflectionMethod $reflected

@return Method
330060
public static function createFromReflection(\ReflectionMethod $reflected)
    {
        $method = new self();
        $method->setName($reflected->getName());

        foreach ($reflected->getParameters() as $parameterReflected) {
            $argument = new Argument();
            $argument->setName($parameterReflected->getName());
            $method->addArgument($argument);
        }

        return $method;
    }
262115
public static function fromReflection(\ReflectionFunctionAbstract $reflection)
    {
        $returnsReference     = $reflection->returnsReference();
        $name                 = $reflection->getShortName();
        $parameterExpressions = self::getParameterExpressionsFromReflection($reflection);

        if ($reflection->isClosure()) {
            return self::closure(
                    $returnsReference,
                    $parameterExpressions,
                    array_keys($reflection->getStaticVariables())
            );
        } elseif ($reflection instanceof \ReflectionMethod) {
            if ($reflection->isPublic()) {
                $accessModifier = self::ACCESS_PUBLIC;
            } elseif ($reflection->isProtected()) {
                $accessModifier = self::ACCESS_PROTECTED;
            } else {
                $accessModifier = self::ACCESS_PRIVATE;
            }

            if ($reflection->isAbstract()) {
                $polymorphModifier = self::POLYMORPH_ABSTRACT;
            } elseif ($reflection->isFinal()) {
                $polymorphModifier = self::POLYMORPH_FINAL;
            } else {
                $polymorphModifier = null;
            }

            return self::method(
                    $returnsReference,
                    $accessModifier,
                    $polymorphModifier,
                    $reflection->isStatic(),
                    $name,
                    $parameterExpressions
            );
        } else {
            return self::func(
                    $returnsReference,
                    $name,
                    $parameterExpressions
            );
        }
    }
1329908
public function create($class) {
        $reflectionClass = new ReflectionClass($class);
        $reflectionMethod = $reflectionClass->getConstructor();
        if (!$reflectionMethod) {
            return new $class;
        }
        $params = &$this->fetchDepsFromSignature($reflectionMethod);
        return $reflectionClass->newInstanceArgs($params);
    }
161593
protected function getMethod(MessageInterface $message, string $prefix = null): Closure
    {
        $name = lcfirst($prefix . $message->getPayloadType()->getName());
        if (method_exists($this, $name) === false) {
            throw new MethodNotFound($message);
        }

        return (new ReflectionMethod($this, $name))->getClosure($this);
    }
1233409
public function callbackReflector($callback): ReflectionFunctionAbstract
    {
        while ($callback instanceof WrappedInvocable) {
            $callback = $callback->callback();
        }

        if (is_array($callback)) {
            return new ReflectionMethod($callback[0], $callback[1]);
        }

        if (is_string($callback) && false !== strpos($callback, '::')) {
            list($className, $methodName) = explode('::', $callback);

            return new ReflectionMethod($className, $methodName);
        }

        if (is_object($callback) && !$callback instanceof Closure) {
            return new ReflectionMethod($callback, '__invoke');
        }

        return new ReflectionFunction($callback);
    }
73768
private function collectMethodCacheAnnotations(ReflectionMethod $method)
    {
        $annotations = array_filter($this->annotationsReader->getMethodAnnotations($method), function ($annotation) {
            return $annotation instanceof CacheAnnotation;
        });

        return new AnnotationCollection($annotations);
    }
467238
private function makeReflection()
    {
        if ($this->reflection === null) {
            $this->reflection = new \ReflectionProperty($this->className, $this->name);

            $this->reflection->setAccessible(true);
        }
    }
274948
protected function _buildCallback(Zend_Server_Reflection_Function_Abstract $reflection)
    {
        $callback = new Zend_Server_Method_Callback();
        if ($reflection instanceof Zend_Server_Reflection_Method) {
            $callback->setType($reflection->isStatic() ? 'static' : 'instance')
                     ->setClass($reflection->getDeclaringClass()->getName())
                     ->setMethod($reflection->getName());
        } elseif ($reflection instanceof Zend_Server_Reflection_Function) {
            $callback->setType('function')
                     ->setFunction($reflection->getName());
        }
        return $callback;
    }
537127
protected function getClassMethods(\ReflectionClass $refClass)
    {
        $methods = [];
        foreach ($refClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
            $methods[$method->name] = $method;
        }

        return $methods;
    }
823003
static function getMethodAnnotations($method, $class = NULL)
	{
		$method instanceof ReflectionMethod or $method = new ReflectionMethod($class, $method);

		return static::instance()->getMethodAnnotations($method);
	}
27577
public static function mixin($mixin)
    {
        $reflection = new \ReflectionClass($mixin);
        $methods = $reflection->getMethods(
            \ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED
        );

        foreach ($methods as $method) {
            $method->setAccessible(true);

            static::macro($method->name, $method->invoke($mixin));
        }
    }
886287
public function callClassMethod($class, $method, ...$arguments)
	{
		$resolvedParameters = [];
		$reflectedClass = new ReflectionCLass($class);
		if (!$reflectedClass->hasMethod($method)) {
			throw new ReflectionException('Call to undefined method ' . $method);
		}

		$methodName = $method;
		$method = $reflectedClass->getMethod($method);
		$methodParameters = $method->getParameters();

		if (count($methodParameters) < 1) {
			return $method;
		}

		$resolvedParameters = array_map(function($param) use ($reflectedClass) {
			$type = $param->getType();

			if (preg_match("/(.*?)\\\/", $type)) {
				$type = (String) $type;
				return new $type;
			}

			if (!$param->isDefaultValueAvailable()) {
				return $param = '';
			}

			return $param->getDefaultValue();
			
		}, $methodParameters);

		$resolvedParameters = array_filter($resolvedParameters);
		$resolvedParameters = array_merge($resolvedParameters, $arguments);

		if ($methodName == '__construct') {
			return $reflectedClass->newInstanceArgs($resolvedParameters);
		}

		return $method->invokeArgs($class, $resolvedParameters);
	}
633451
private function generateMethodCode(\ReflectionMethod $rm) : array
    {
        $method_name     = $rm->getName();
        $modifiers       = $rm->getModifiers();
        $params          = $rm->getParameters();
        $has_return_type = $rm->hasReturnType();
        $return_type     = $rm->getReturnType();
        
        $is_static = Util::isAllBitSet($modifiers, \ReflectionMethod::IS_STATIC);
        
        // method body
        $method_body = '';
        if ($has_return_type){
            // pseudo code with return value
            $method_body .= 'return ' . self::generatePseudoReturnCode($return_type) . ';';
        }
    
        // generate code
        $parameters_code = [];
        foreach($params as $rp){
            $parameters_code[] = self::generateParameterPrototypeCode($rp);
        }
        $parameters_code = implode(', ', $parameters_code);
        
        $return_type_part = '';
        if ($has_return_type){
            $return_type_part .= ' : ';
            $return_type_part .= self::generateReturnTypeCode($return_type);
        }
        
        $prototype = Code::PHP_PUBLIC . ' ' . ($is_static ? Code::PHP_STATIC . ' ' : '') . Code::PHP_FUNCTION . ' '
                        . $method_name . '(' . $parameters_code . ')' . $return_type_part;
        
        $code[] = Code::INDENT . $prototype;
        $code[] = Code::INDENT . '{';
        if (!empty($method_body)){
            $code[] = Code::INDENT . Code::INDENT . $method_body;
        }
        $code[] = Code::INDENT . '}';
        
        return $code;
    }
457142
protected function buildMethod(ReflectionMethod $reflectionMethod) : Node\Stmt\ClassMethod
    {
        $methodBuilder = new Method($reflectionMethod->getName());

        if ($reflectionMethod->isPublic()) {
            $methodBuilder->makePublic();
        }

        if ($reflectionMethod->isProtected()) {
            $methodBuilder->makeProtected();
        }

        if ($reflectionMethod->isPrivate()) {
            $methodBuilder->makePrivate();
        }

        if ($reflectionMethod->isStatic()) {
            $methodBuilder->makeStatic();
        }

        if ($reflectionMethod->isAbstract()) {
            $methodBuilder->makeAbstract();
        }

        if ($reflectionMethod->isFinal()) {
            $methodBuilder->makeFinal();
        }

        if ($reflectionMethod->returnsReference()) {
            $methodBuilder->makeReturnByRef();
        }

        foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
            $methodBuilder->addParam($this->buildParameter($reflectionParameter));
        }

        // @todo should parse method body if possible (skipped for now)

        return $methodBuilder->getNode();
    }
177351
public function getMethods($filter = \ReflectionProperty::IS_PUBLIC)
    {
        $methods = array();
        $reflectionMethods = $this->reflectionEntity->getMethods($filter);
        foreach ($reflectionMethods as $method) {
            $methods[] = new Method($method->name, $method->isStatic());
        }

        return $methods;
    }
1330675
private function getOnValidate(\ReflectionMethod $method)
    {
        /** @var $valid Valid */
        $valid = $this->reader->getMethodAnnotation($method, Valid::class);
        $class = $method->getDeclaringClass();
        $onMethods = $this->findOnMethods($class, $valid);
        if ($onMethods[0] && $onMethods[0] instanceof \ReflectionMethod) {
            return $onMethods;
        }
        throw new ValidateMethodNotFound($method->getShortName());
    }
1054796
public function replay()
    {
        $mockClassName = parent::replay();

        $mockClassReflector = new \ReflectionClass($mockClassName);
        return $mockClassReflector->newInstanceArgs($this->constructor_arguments);
    }