Skip to content

Commit 5e91023

Browse files
committed
Merge pull request #812 from pyrech/fix-811
Fixed exception message in ParamFetcher
2 parents 4cc697b + f0c6149 commit 5e91023

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Request/ParamFetcher.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public function get($name, $strict = null)
8383
$config = $this->params[$name];
8484
$nullable = $config->nullable;
8585
$default = $config->default;
86+
$paramType = $config instanceof QueryParam ? 'Query' : 'Request';
8687

8788
if ($config->array) {
8889
$default = (array) $default;
@@ -103,7 +104,9 @@ public function get($name, $strict = null)
103104
if ($config->array) {
104105
if (!is_array($param)) {
105106
if ($strict) {
106-
throw new BadRequestHttpException(sprintf("Query parameter value of '%s' is not an array", $name));
107+
throw new BadRequestHttpException(
108+
sprintf("% parameter value of '%s' is not an array", $paramType, $name)
109+
);
107110
}
108111

109112
return $default;
@@ -120,7 +123,6 @@ public function get($name, $strict = null)
120123
if (!is_scalar($param)) {
121124
if (!$nullable) {
122125
if ($strict) {
123-
$paramType = $config instanceof QueryParam ? 'Query' : 'Request';
124126
$problem = empty($param) ? 'empty' : 'not a scalar';
125127

126128
throw new BadRequestHttpException(
@@ -150,6 +152,7 @@ public function get($name, $strict = null)
150152
public function cleanParamWithRequirements(Param $config, $param, $strict)
151153
{
152154
$default = $config->default;
155+
$paramType = $config instanceof QueryParam ? 'Query' : 'Request';
153156

154157
if (null !== $config->requirements && null === $this->validator) {
155158
throw new \RuntimeException(
@@ -166,7 +169,9 @@ public function cleanParamWithRequirements(Param $config, $param, $strict)
166169
if (is_scalar($constraint)) {
167170
if (is_array($param)) {
168171
if ($strict) {
169-
throw new BadRequestHttpException("Query parameter is an array");
172+
throw new BadRequestHttpException(
173+
sprintf("%s parameter is an array", $paramType)
174+
);
170175
}
171176

172177
return $default;
@@ -176,7 +181,7 @@ public function cleanParamWithRequirements(Param $config, $param, $strict)
176181
'pattern' => '#^'.$config->requirements.'$#xsu',
177182
'message' => sprintf(
178183
"%s parameter value '%s', does not match requirements '%s'",
179-
$config instanceof QueryParam ? 'Query' : 'Request',
184+
$paramType,
180185
$param,
181186
$config->requirements
182187
)

0 commit comments

Comments
 (0)