Skip to content

Commit d3003bf

Browse files
committed
Revert "ComponentReflection::combineArgs() throws InvalidArgumentException instead BadRequestException when incompatible type is object"
This reverts commit 212ec43.
1 parent 3c9a289 commit d3003bf

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

src/Application/UI/ComponentReflection.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,10 @@ 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;
129128
if (isset($args[$name])) {
130129
$res[$i] = $args[$name];
131130
if (!self::convertType($res[$i], $type, $isClass)) {
132-
throw new $exception(sprintf(
131+
throw new BadRequestException(sprintf(
133132
'Argument $%s passed to %s() must be %s, %s given.',
134133
$name,
135134
($method instanceof \ReflectionMethod ? $method->getDeclaringClass()->getName() . '::' : '') . $method->getName(),
@@ -144,7 +143,7 @@ public static function combineArgs(\ReflectionFunctionAbstract $method, $args)
144143
} elseif ($type === 'array') {
145144
$res[$i] = [];
146145
} else {
147-
throw new $exception(sprintf(
146+
throw new BadRequestException(sprintf(
148147
'Missing parameter $%s required by %s()',
149148
$name,
150149
($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-
}, Nette\InvalidArgumentException::class, 'Missing parameter $req required by MyPresenter::objects()');
193+
}, BadRequestException::class, 'Missing parameter $req required by MyPresenter::objects()');
194194

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

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

tests/UI/ComponentReflection.combineArgs.php71.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-
}, Nette\InvalidArgumentException::class, 'Missing parameter $req required by MyPresenter::objects()');
193+
}, Nette\Application\BadRequestException::class, 'Missing parameter $req required by MyPresenter::objects()');
194194

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

199199
Assert::exception(function () use ($method) {
200200
Reflection::combineArgs($method, ['req' => $method, 'opt' => NULL]);
201-
}, Nette\InvalidArgumentException::class, 'Argument $req passed to MyPresenter::objects() must be stdClass, ReflectionMethod given.');
201+
}, Nette\Application\BadRequestException::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-
}, Nette\InvalidArgumentException::class, 'Argument $req passed to MyPresenter::objects() must be stdClass, array given.');
205+
}, Nette\Application\BadRequestException::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-
}, Nette\InvalidArgumentException::class, 'Missing parameter $req required by MyPresenter::objects()');
75+
}, BadRequestException::class, 'Missing parameter $req required by MyPresenter::objects()');
7676

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

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

0 commit comments

Comments
 (0)