Skip to content

Commit 212ec43

Browse files
committed
ComponentReflection::combineArgs() throws InvalidArgumentException instead BadRequestException when incompatible type is object
1 parent 5d211e0 commit 212ec43

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/Application/UI/ComponentReflection.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,11 @@ public static function combineArgs(\ReflectionFunctionAbstract $method, $args)
125125
foreach ($method->getParameters() as $i => $param) {
126126
$name = $param->getName();
127127
list($type, $isClass) = self::getParameterType($param);
128+
$exception = $isClass ? Nette\InvalidArgumentException::class : BadRequestException::class;
128129
if (isset($args[$name])) {
129130
$res[$i] = $args[$name];
130131
if (!self::convertType($res[$i], $type, $isClass)) {
131-
throw new BadRequestException(sprintf(
132+
throw new $exception(sprintf(
132133
'Argument $%s passed to %s() must be %s, %s given.',
133134
$name,
134135
($method instanceof \ReflectionMethod ? $method->getDeclaringClass()->getName() . '::' : '') . $method->getName(),
@@ -143,7 +144,7 @@ public static function combineArgs(\ReflectionFunctionAbstract $method, $args)
143144
} elseif ($type === 'NULL') {
144145
$res[$i] = NULL;
145146
} else {
146-
throw new BadRequestException(sprintf(
147+
throw new $exception(sprintf(
147148
'Missing parameter $%s required by %s()',
148149
$name,
149150
($method instanceof \ReflectionMethod ? $method->getDeclaringClass()->getName() . '::' : '') . $method->getName()

tests/UI/ComponentReflection.combineArgs.php7.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,17 @@ test(function () {
190190

191191
Assert::exception(function () use ($method) {
192192
Reflection::combineArgs($method, []);
193-
}, BadRequestException::class, 'Missing parameter $req required by MyPresenter::objects()');
193+
}, Nette\InvalidArgumentException::class, 'Missing parameter $req required by MyPresenter::objects()');
194194

195195
Assert::exception(function () use ($method) {
196196
Reflection::combineArgs($method, ['req' => NULL, 'opt' => NULL]);
197-
}, BadRequestException::class, 'Missing parameter $req required by MyPresenter::objects()');
197+
}, Nette\InvalidArgumentException::class, 'Missing parameter $req required by MyPresenter::objects()');
198198

199199
Assert::exception(function () use ($method) {
200200
Reflection::combineArgs($method, ['req' => $method, 'opt' => NULL]);
201-
}, BadRequestException::class, 'Argument $req passed to MyPresenter::objects() must be stdClass, ReflectionMethod given.');
201+
}, Nette\InvalidArgumentException::class, 'Argument $req passed to MyPresenter::objects() must be stdClass, ReflectionMethod given.');
202202

203203
Assert::exception(function () use ($method) {
204204
Reflection::combineArgs($method, ['req' => [], 'opt' => NULL]);
205-
}, BadRequestException::class, 'Argument $req passed to MyPresenter::objects() must be stdClass, array given.');
205+
}, Nette\InvalidArgumentException::class, 'Argument $req passed to MyPresenter::objects() must be stdClass, array given.');
206206
});

tests/UI/ComponentReflection.combineArgs.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ test(function () {
7272

7373
Assert::exception(function () use ($method) {
7474
Reflection::combineArgs($method, []);
75-
}, BadRequestException::class, 'Missing parameter $req required by MyPresenter::objects()');
75+
}, Nette\InvalidArgumentException::class, 'Missing parameter $req required by MyPresenter::objects()');
7676

7777
Assert::exception(function () use ($method) {
7878
Reflection::combineArgs($method, ['req' => NULL, 'opt' => NULL]);
79-
}, BadRequestException::class, 'Missing parameter $req required by MyPresenter::objects()');
79+
}, Nette\InvalidArgumentException::class, 'Missing parameter $req required by MyPresenter::objects()');
8080

8181
Assert::exception(function () use ($method) {
8282
Reflection::combineArgs($method, ['req' => $method, 'opt' => NULL]);
83-
}, BadRequestException::class, 'Argument $req passed to MyPresenter::objects() must be stdClass, ReflectionMethod given.');
83+
}, Nette\InvalidArgumentException::class, 'Argument $req passed to MyPresenter::objects() must be stdClass, ReflectionMethod given.');
8484
});

0 commit comments

Comments
 (0)