From dfcaaca4b9cfa7e722c3cfc169b2b2e6c7f6461b Mon Sep 17 00:00:00 2001 From: Tom Butler Date: Tue, 28 Jan 2020 13:46:54 +0000 Subject: [PATCH] Better scalar matching when there are multiple sources e.g. constructParams and --- Dice.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Dice.php b/Dice.php index 39ddeef..2ba9ec6 100644 --- a/Dice.php +++ b/Dice.php @@ -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);