Skip to content

Commit 7e84df3

Browse files
committed
Move parameters validation to encodeApplicationJson method
1 parent 36ce701 commit 7e84df3

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/Codeception/Module/REST.php

+9-7
Original file line numberDiff line numberDiff line change
@@ -648,13 +648,6 @@ protected function execute($method, $url, $parameters = [], $files = [])
648648
}
649649
} else {
650650
$parameters = $this->encodeApplicationJson($method, $parameters);
651-
652-
if (!is_string($parameters) && !is_array($parameters)) {
653-
if ($parameters instanceof \JsonSerializable) {
654-
throw new ModuleException(__CLASS__, $method . ' parameters is JsonSerializable object, but Content-Type header is not set to application/json');
655-
}
656-
throw new ModuleException(__CLASS__, $method . ' parameters must be array, string or object implementing JsonSerializable interface');
657-
}
658651
}
659652

660653
if (is_array($parameters) || $isQueryParamsAwareMethod) {
@@ -735,6 +728,15 @@ protected function encodeApplicationJson($method, $parameters)
735728
return json_encode($parameters);
736729
}
737730
}
731+
732+
if ($parameters instanceof \JsonSerializable) {
733+
throw new ModuleException(__CLASS__, $method . ' parameters is JsonSerializable object, but Content-Type header is not set to application/json');
734+
}
735+
736+
if (!is_string($parameters) && !is_array($parameters)) {
737+
throw new ModuleException(__CLASS__, $method . ' parameters must be array, string or object implementing JsonSerializable interface');
738+
}
739+
738740
return $parameters;
739741
}
740742

0 commit comments

Comments
 (0)