Skip to content

Commit 03a4a2c

Browse files
author
Fredrick Peter
committed
Collection Update
1 parent dfd3f56 commit 03a4a2c

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/Collections/Traits/RelatedTrait.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ private function convertMapperOnInit(mixed $items = null)
231231
return json_decode(json_encode($items), true);
232232
} elseif (is_array($items)) {
233233
return $items;
234-
} elseif ($this->isValidJson((string) $items)) {
234+
} elseif ($this->isValidJson($items)) {
235235
return json_decode($items, true);
236236
}
237237

@@ -251,7 +251,7 @@ private function convertOnInit(mixed $items = null)
251251
return json_decode(json_encode($items), true);
252252
} elseif(is_array($items)){
253253
return $items;
254-
} elseif($this->isValidJson((string) $items)) {
254+
} elseif($this->isValidJson($items)) {
255255
return json_decode($items, true);
256256
}
257257

@@ -261,13 +261,17 @@ private function convertOnInit(mixed $items = null)
261261
/**
262262
* Check if a string is valid JSON.
263263
*
264-
* @param string $data
264+
* @param mixed $data
265265
* @return bool
266266
*/
267-
private function isValidJson(?string $data = null)
267+
private function isValidJson(mixed $data = null)
268268
{
269-
json_decode($data);
270-
return json_last_error() === JSON_ERROR_NONE;
269+
if(is_string($data)){
270+
json_decode($data);
271+
return json_last_error() === JSON_ERROR_NONE;
272+
}
273+
274+
return false;
271275
}
272276

273277
}

0 commit comments

Comments
 (0)