From 9e5b779abc74e7d4a8045a4b96fcf7802f4bbaf0 Mon Sep 17 00:00:00 2001 From: jordanbrauer <18744334+jordanbrauer@users.noreply.github.com> Date: Wed, 16 Jun 2021 00:52:31 -0500 Subject: [PATCH] feat: add helper function for mapping a function's arguments --- src/Support/Reflection.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Support/Reflection.php b/src/Support/Reflection.php index c25709b9..1fac05b7 100644 --- a/src/Support/Reflection.php +++ b/src/Support/Reflection.php @@ -153,4 +153,21 @@ final class Reflection return $name; } + + /** + * Receive a map of function argument names to their types. + * + * @return array + */ + public static function getFunctionArguments(Closure $function): array + { + $parameters = (new ReflectionFunction($function))->getParameters(); + $arguments = []; + + foreach ($parameters as $parameter) { + $arguments[$parameter->getName()] = ($parameter->hasType()) ? $parameter->getType() : 'mixed'; + } + + return $arguments; + } }