/** * Creates a function location instance from the supplied reflection. * * @param \ReflectionFunctionAbstract $reflection * * @return self */ public static function fromReflection(\ReflectionFunctionAbstract $reflection) { if ($reflection instanceof \ReflectionFunction) { $namespace = $reflection->getNamespaceName(); } elseif ($reflection instanceof \ReflectionMethod) { $namespace = $reflection->getDeclaringClass()->getNamespaceName(); } else { $namespace = null; } return new self($reflection->getFileName(), $namespace, $reflection->getStartLine(), $reflection->getEndLine()); }
/** * @param ParamNode $node * @param ReflectionFunctionAbstract $function * @param int $parameterIndex * @return ReflectionParameter */ public static function createFromNode(ParamNode $node, ReflectionFunctionAbstract $function, $parameterIndex) { $param = new self(); $param->name = $node->name; $param->function = $function; $param->isOptional = (bool) $node->isOptional; $param->hasDefaultValue = null !== $node->default; $param->isVariadic = (bool) $node->variadic; $param->isByReference = (bool) $node->byRef; $param->parameterIndex = (int) $parameterIndex; $param->typeHint = (new FindTypeFromAst())->__invoke($node->type, $function->getLocatedSource(), $function instanceof ReflectionMethod ? $function->getDeclaringClass()->getNamespaceName() : $function->getNamespaceName()); if ($param->hasDefaultValue) { $param->parseDefaultValueNode($node->default); } $param->docBlockTypes = (new FindParameterType())->__invoke($function, $node); return $param; }
/** * Get the type hint declared for the parameter. This is the real type hint * for the parameter, e.g. `method(closure $someFunc)` defined by the * method itself, and is separate from the docblock type hints. * * @see getDocBlockTypes() * @return Type */ public function getTypeHint() { $namespaceForType = $this->function instanceof ReflectionMethod ? $this->function->getDeclaringClass()->getNamespaceName() : $this->function->getNamespaceName(); return (new FindTypeFromAst())->__invoke($this->node->type, $this->function->getLocatedSource(), $namespaceForType); }