Skip to content

Commit

Permalink
Better scalar matching when there are multiple sources e.g. construct…
Browse files Browse the repository at this point in the history
…Params and
  • Loading branch information
TRPB committed Jan 28, 2020
1 parent 2fea274 commit dfcaaca
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Dice.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,18 @@ private function getParams(\ReflectionMethod $method, array $rule) {
catch (\InvalidArgumentException $e) {
}
// Support PHP 7 scalar type hinting, is_a('string', 'foo') doesn't work so this is a hacky AF workaround: call_user_func('is_' . $type, '')
else if ($args && (!$param->getType() || call_user_func('is_' . $param->getType()->__toString(), $args[0]))) $parameters[] = $this->expand(array_shift($args));

//Find a match in $args for scalar types
else if ($args && $param->getType()) {
for ($i = 0; $i < count($args); $i++) {
if (call_user_func('is_' . $param->getType()->getName(), $args[$i])) {
$parameters[] = array_splice($args, $i, 1)[0];
}
}
}
else if ($args) {
$parameters[] = $this->expand(array_shift($args));
}
// For variadic parameters, provide remaining $args
else if ($param->isVariadic()) {
$parameters = array_merge($parameters, $args);
Expand Down

0 comments on commit dfcaaca

Please sign in to comment.