mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 08:17:22 +01:00
feat: add helper function for mapping a function's arguments
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user