From 550c07bcb7dc21bcfbdadbcf8e93d87e69820ad0 Mon Sep 17 00:00:00 2001 From: aB0t Date: Tue, 23 Jan 2024 07:44:03 +0200 Subject: [PATCH] update 2024-01-23 07:44:03 --- .../code.php | 16 +++++++++------- .../code.power | 16 +++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/c99e85a0-d120-4f25-bcbf-0940dd7b773b/code.php b/src/c99e85a0-d120-4f25-bcbf-0940dd7b773b/code.php index 4264c8a..b6a726a 100644 --- a/src/c99e85a0-d120-4f25-bcbf-0940dd7b773b/code.php +++ b/src/c99e85a0-d120-4f25-bcbf-0940dd7b773b/code.php @@ -62,25 +62,26 @@ final class Response **/ protected function getBody(JoomlaResponse $response, $default = null) { + $body = $response->body ?? null; // 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 (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 libxml_use_internal_errors(true); - $xml = simplexml_load_string($response->body); + $xml = simplexml_load_string($body); if ($xml !== false) { return $xml; } // if it's neither JSON nor XML, return as is - return $response->body; + return $body; } return $default; @@ -96,10 +97,11 @@ final class Response **/ protected function error(JoomlaResponse $response): string { + $body = $response->body ?? null; // 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 { diff --git a/src/c99e85a0-d120-4f25-bcbf-0940dd7b773b/code.power b/src/c99e85a0-d120-4f25-bcbf-0940dd7b773b/code.power index f29c159..3940577 100644 --- a/src/c99e85a0-d120-4f25-bcbf-0940dd7b773b/code.power +++ b/src/c99e85a0-d120-4f25-bcbf-0940dd7b773b/code.power @@ -36,25 +36,26 @@ **/ protected function getBody(JoomlaResponse $response, $default = null) { + $body = $response->body ?? null; // 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 (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 libxml_use_internal_errors(true); - $xml = simplexml_load_string($response->body); + $xml = simplexml_load_string($body); if ($xml !== false) { return $xml; } // if it's neither JSON nor XML, return as is - return $response->body; + return $body; } return $default; @@ -70,10 +71,11 @@ **/ protected function error(JoomlaResponse $response): string { + $body = $response->body ?? null; // 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 {