Skip to content

Commit 0667abc

Browse files
committed
PresenterComponentReflection::combineArgs() should retype variables in the $res array. [Fixes #99]
Use foreach's automatic indexing instead of manual one.
1 parent 1ad183b commit 0667abc

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/Application/UI/PresenterComponentReflection.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,14 @@ public function hasCallableMethod($method)
117117
public static function combineArgs(\ReflectionFunctionAbstract $method, $args)
118118
{
119119
$res = [];
120-
$i = 0;
121-
foreach ($method->getParameters() as $param) {
120+
foreach ($method->getParameters() as $i => $param) {
122121
$name = $param->getName();
123122
if (!isset($args[$name]) && $param->isDefaultValueAvailable()) {
124-
$res[$i++] = $param->getDefaultValue();
123+
$res[$i] = $param->getDefaultValue();
125124
} else {
126-
$res[$i++] = $arg = isset($args[$name]) ? $args[$name] : NULL;
125+
$res[$i] = $arg = isset($args[$name]) ? $args[$name] : NULL;
127126
list($type, $isClass) = self::getParameterType($param);
128-
if (!self::convertType($arg, $type, $isClass)) {
127+
if (!self::convertType($res[$i], $type, $isClass)) {
129128
throw new BadRequestException(sprintf(
130129
'Argument $%s passed to %s() must be %s, %s given.',
131130
$name,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* Test: PresenterComponentReflection::combineArgs()
5+
*/
6+
7+
use Nette\Application\UI\PresenterComponentReflection;
8+
use Tester\Assert;
9+
10+
require __DIR__ . '/../bootstrap.php';
11+
12+
class MyPresenter
13+
{
14+
15+
public function myMethod($intParam = 0, $strParam = '')
16+
{
17+
}
18+
19+
}
20+
21+
$reflection = new ReflectionMethod('MyPresenter', 'myMethod');
22+
23+
Assert::same([10, 'str'], PresenterComponentReflection::combineArgs($reflection, ['intParam' => '10', 'strParam' => 'str']));
24+
Assert::same([0, ''], PresenterComponentReflection::combineArgs($reflection, []));

0 commit comments

Comments
 (0)