feat: add helper function for mapping a function's arguments

This commit is contained in:
jordanbrauer
2021-06-16 00:52:31 -05:00
parent 729638a3bb
commit 9e5b779abc

View File

@ -153,4 +153,21 @@ final class Reflection
return $name;
}
/**
* Receive a map of function argument names to their types.
*
* @return array<string, string>
*/
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;
}
}