4
0

update 2024-01-23 07:44:03

This commit is contained in:
Robot 2024-01-23 07:44:03 +02:00
parent b36798318c
commit 550c07bcb7
Signed by: Robot
GPG Key ID: 14DECD44E7E1BB95
2 changed files with 18 additions and 14 deletions

View File

@ -62,25 +62,26 @@ final class Response
**/ **/
protected function getBody(JoomlaResponse $response, $default = null) protected function getBody(JoomlaResponse $response, $default = null)
{ {
$body = $response->body ?? null;
// check that we have a body // check that we have a body
if (isset($response->body) && StringHelper::check($response->body)) if (StringHelper::check($body))
{ {
// if it's JSON, decode it // if it's JSON, decode it
if (JsonHelper::check($response->body)) if (JsonHelper::check($body))
{ {
return json_decode((string) $response->body); return json_decode((string) $body);
} }
// if it's XML, convert it to an object // if it's XML, convert it to an object
libxml_use_internal_errors(true); libxml_use_internal_errors(true);
$xml = simplexml_load_string($response->body); $xml = simplexml_load_string($body);
if ($xml !== false) if ($xml !== false)
{ {
return $xml; return $xml;
} }
// if it's neither JSON nor XML, return as is // if it's neither JSON nor XML, return as is
return $response->body; return $body;
} }
return $default; return $default;
@ -96,10 +97,11 @@ final class Response
**/ **/
protected function error(JoomlaResponse $response): string protected function error(JoomlaResponse $response): string
{ {
$body = $response->body ?? null;
// do we have a json string // do we have a json string
if (isset($response->body) && JsonHelper::check($response->body)) if (JsonHelper::check($body))
{ {
$error = json_decode($response->body); $error = json_decode($body);
} }
else else
{ {

View File

@ -36,25 +36,26 @@
**/ **/
protected function getBody(JoomlaResponse $response, $default = null) protected function getBody(JoomlaResponse $response, $default = null)
{ {
$body = $response->body ?? null;
// check that we have a body // check that we have a body
if (isset($response->body) && StringHelper::check($response->body)) if (StringHelper::check($body))
{ {
// if it's JSON, decode it // if it's JSON, decode it
if (JsonHelper::check($response->body)) if (JsonHelper::check($body))
{ {
return json_decode((string) $response->body); return json_decode((string) $body);
} }
// if it's XML, convert it to an object // if it's XML, convert it to an object
libxml_use_internal_errors(true); libxml_use_internal_errors(true);
$xml = simplexml_load_string($response->body); $xml = simplexml_load_string($body);
if ($xml !== false) if ($xml !== false)
{ {
return $xml; return $xml;
} }
// if it's neither JSON nor XML, return as is // if it's neither JSON nor XML, return as is
return $response->body; return $body;
} }
return $default; return $default;
@ -70,10 +71,11 @@
**/ **/
protected function error(JoomlaResponse $response): string protected function error(JoomlaResponse $response): string
{ {
$body = $response->body ?? null;
// do we have a json string // do we have a json string
if (isset($response->body) && JsonHelper::check($response->body)) if (JsonHelper::check($body))
{ {
$error = json_decode($response->body); $error = json_decode($body);
} }
else else
{ {