From 8e87ae81c2098abd7895bfd96d9fac1cd332abc3 Mon Sep 17 00:00:00 2001 From: Peter Uhnak Date: Tue, 13 Oct 2015 11:08:37 +0200 Subject: [PATCH] PresenterComponentReflection::combineArgs() should retype variables in the $res array. [Fixes #99] Use foreach's automatic indexing instead of manual one. --- .../UI/PresenterComponentReflection.php | 9 ++++--- ...senterComponentReflection.combineArgs.phpt | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 tests/UI/PresenterComponentReflection.combineArgs.phpt diff --git a/src/Application/UI/PresenterComponentReflection.php b/src/Application/UI/PresenterComponentReflection.php index b9439dd0d..5627a405b 100644 --- a/src/Application/UI/PresenterComponentReflection.php +++ b/src/Application/UI/PresenterComponentReflection.php @@ -117,15 +117,14 @@ public function hasCallableMethod($method) public static function combineArgs(\ReflectionFunctionAbstract $method, $args) { $res = array(); - $i = 0; - foreach ($method->getParameters() as $param) { + foreach ($method->getParameters() as $i => $param) { $name = $param->getName(); if (!isset($args[$name]) && $param->isDefaultValueAvailable()) { - $res[$i++] = $param->getDefaultValue(); + $res[$i] = $param->getDefaultValue(); } else { - $res[$i++] = $arg = isset($args[$name]) ? $args[$name] : NULL; + $res[$i] = $arg = isset($args[$name]) ? $args[$name] : NULL; list($type, $isClass) = self::getParameterType($param); - if (!self::convertType($arg, $type, $isClass)) { + if (!self::convertType($res[$i], $type, $isClass)) { throw new BadRequestException(sprintf( 'Argument $%s passed to %s() must be %s, %s given.', $name, diff --git a/tests/UI/PresenterComponentReflection.combineArgs.phpt b/tests/UI/PresenterComponentReflection.combineArgs.phpt new file mode 100644 index 000000000..d94696b51 --- /dev/null +++ b/tests/UI/PresenterComponentReflection.combineArgs.phpt @@ -0,0 +1,24 @@ + '10', 'strParam' => 'str'))); +Assert::same(array(0, ''), PresenterComponentReflection::combineArgs($reflection, array()));