/**
* @param string $function_name
* The name of the function we'd like to look up
*
* @param bool $is_function_declaration
* This must be set to true if we're getting a function
* that is being declared and false if we're getting a
* function being called.
*
* @return FunctionInterface
* A method with the given name in the given context
*
* @throws IssueException
* An exception is thrown if we can't find the given
* function
*/
public function getFunction(string $function_name, bool $is_function_declaration = false) : FunctionInterface
{
if ($is_function_declaration) {
$function_fqsen = FullyQualifiedFunctionName::make($this->context->getNamespace(), $function_name);
} else {
$function_fqsen = FullyQualifiedFunctionName::make($this->context->getNamespace(), $function_name);
// If it doesn't exist in the local namespace, try it
// in the global namespace
if (!$this->code_base->hasFunctionWithFQSEN($function_fqsen)) {
$function_fqsen = FullyQualifiedFunctionName::fromStringInContext($function_name, $this->context);
}
}
// Make sure the method we're calling actually exists
if (!$this->code_base->hasFunctionWithFQSEN($function_fqsen)) {
throw new IssueException(Issue::fromType(Issue::UndeclaredFunction)($this->context->getFile(), $this->node->lineno ?? 0, ["{$function_fqsen}()"]));
}
return $this->code_base->getFunctionByFQSEN($function_fqsen);
}