Skip to content

Commit 75ffade

Browse files
authored
Prevent "Warning: Invalid argument supplied for foreach() in [...]\ve… (#47)
* Prevent "Warning: Invalid argument supplied for foreach() in Response\JSON.php on line 143" warnings if the $value for the self::camelizeObject($value); line is NULL. * Check to only pass an object to camelizeObject when parsing and also enforce the data type being processed by it.
1 parent 0086e49 commit 75ffade

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Response/JSON.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function parse($data, array $headers)
100100
$this->headers = $headers;
101101
$this->string = json_encode($source);
102102

103-
$this->data = self::camelizeObject($source);
103+
$this->data = is_object($source) ? self::camelizeObject($source) : $source;
104104

105105
if (!empty($this->data->id)) {
106106
$this->data->id = (int) $this->data->id;
@@ -139,6 +139,10 @@ protected function getContent()
139139
*/
140140
protected static function camelizeObject($source)
141141
{
142+
if (!is_object($source) && !is_array($source)) {
143+
return $source;
144+
}
145+
142146
$destination = new ArrayObject([], ArrayObject::ARRAY_AS_PROPS);
143147
foreach ($source as $key => $value) {
144148
if (ctype_upper($key)) {

0 commit comments

Comments
 (0)