Skip to content

Commit 8f91b06

Browse files
committed
Made more readable 'prepareResult' method
1 parent 786b231 commit 8f91b06

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/JsonQueriable.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,23 +170,21 @@ public function isJson($value, $return_map = false)
170170

171171
return (json_last_error() == JSON_ERROR_NONE) ? ($return_map ? $data : true) : json_last_error_msg();
172172
}
173-
protected function prepareResult($data, $object)
173+
174+
/**
175+
* @param mixed $data
176+
* @param bool $isObject
177+
* @return array
178+
*/
179+
protected function prepareResult($data, $isObject)
174180
{
175181
$output = [];
176182
if (is_array($data)) {
177183
foreach ($data as $key => $val) {
178-
if ($object) {
179-
$output[$key] = (object) $val;
180-
} else {
181-
$output[$key] = $val;
182-
}
184+
$output[$key] = $isObject ? (object) $val : $val;
183185
}
184186
} else {
185-
if ($object) {
186-
$output = json_decode(json_encode($data));
187-
} else {
188-
$output = json_decode(json_encode($data), true);
189-
}
187+
$output = json_decode(json_encode($data), $isObject);
190188
}
191189

192190
return $output;

0 commit comments

Comments
 (0)