From ffca82f0be00beebec168923a8ef42db4f5c1891 Mon Sep 17 00:00:00 2001 From: yangpeng <183851063@qq.com> Date: Wed, 29 Mar 2023 18:14:20 +0800 Subject: [PATCH] modify empty judgment --- src/OSS/Core/OssUtil.php | 2 +- src/OSS/Result/AclResult.php | 2 +- src/OSS/Result/BodyResult.php | 2 +- src/OSS/Result/GetBucketInfoResult.php | 5 ++--- src/OSS/Result/GetLocationResult.php | 8 +++----- src/OSS/Result/GetStorageCapacityResult.php | 4 ++-- tests/OSS/Tests/BodyResultTest.php | 15 +++++++++++++++ 7 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/OSS/Core/OssUtil.php b/src/OSS/Core/OssUtil.php index 93e2f4ff..df54669d 100644 --- a/src/OSS/Core/OssUtil.php +++ b/src/OSS/Core/OssUtil.php @@ -211,7 +211,7 @@ public static function validateOptions($options) */ public static function validateContent($content) { - if (empty($content)) { + if (!isset($content) || $content === "") { throw new OssException("http body content is invalid"); } } diff --git a/src/OSS/Result/AclResult.php b/src/OSS/Result/AclResult.php index 7061ff09..49e5cd09 100644 --- a/src/OSS/Result/AclResult.php +++ b/src/OSS/Result/AclResult.php @@ -18,7 +18,7 @@ class AclResult extends Result protected function parseDataFromResponse() { $content = $this->rawResponse->body; - if (empty($content)) { + if (!isset($content) || $content === "") { throw new OssException("body is null"); } $xml = simplexml_load_string($content); diff --git a/src/OSS/Result/BodyResult.php b/src/OSS/Result/BodyResult.php index 44ba15ef..0def2de4 100644 --- a/src/OSS/Result/BodyResult.php +++ b/src/OSS/Result/BodyResult.php @@ -14,6 +14,6 @@ class BodyResult extends Result */ protected function parseDataFromResponse() { - return empty($this->rawResponse->body) ? "" : $this->rawResponse->body; + return isset($this->rawResponse->body) && $this->rawResponse->body !== "" ? $this->rawResponse->body :""; } } \ No newline at end of file diff --git a/src/OSS/Result/GetBucketInfoResult.php b/src/OSS/Result/GetBucketInfoResult.php index ad55e95b..3925d3df 100644 --- a/src/OSS/Result/GetBucketInfoResult.php +++ b/src/OSS/Result/GetBucketInfoResult.php @@ -15,14 +15,13 @@ class GetBucketInfoResult extends Result { /** * Parse data from response - * - * @return string + * @return BucketInfo * @throws OssException */ protected function parseDataFromResponse() { $content = $this->rawResponse->body; - if (empty($content)) { + if (!isset($content) || $content === "") { throw new OssException("body is null"); } $xml = simplexml_load_string($content); diff --git a/src/OSS/Result/GetLocationResult.php b/src/OSS/Result/GetLocationResult.php index a0c51295..2bc63ae8 100644 --- a/src/OSS/Result/GetLocationResult.php +++ b/src/OSS/Result/GetLocationResult.php @@ -14,17 +14,15 @@ class GetLocationResult extends Result /** * Parse data from response - * - * @return string + * @return false|\SimpleXMLElement|string|null * @throws OssException */ protected function parseDataFromResponse() { $content = $this->rawResponse->body; - if (empty($content)) { + if (!isset($content) || $content === "") { throw new OssException("body is null"); } - $xml = simplexml_load_string($content); - return $xml; + return simplexml_load_string($content); } } \ No newline at end of file diff --git a/src/OSS/Result/GetStorageCapacityResult.php b/src/OSS/Result/GetStorageCapacityResult.php index 2f4127b1..76a26a52 100644 --- a/src/OSS/Result/GetStorageCapacityResult.php +++ b/src/OSS/Result/GetStorageCapacityResult.php @@ -15,13 +15,13 @@ class GetStorageCapacityResult extends Result /** * Parse data from response * - * @return string + * @return int * @throws OssException */ protected function parseDataFromResponse() { $content = $this->rawResponse->body; - if (empty($content)) { + if (!isset($content) || $content === "") { throw new OssException("body is null"); } $xml = simplexml_load_string($content); diff --git a/tests/OSS/Tests/BodyResultTest.php b/tests/OSS/Tests/BodyResultTest.php index 290e61ab..f990515a 100644 --- a/tests/OSS/Tests/BodyResultTest.php +++ b/tests/OSS/Tests/BodyResultTest.php @@ -14,6 +14,21 @@ public function testParseValid200() $result = new BodyResult($response); $this->assertTrue($result->isOK()); $this->assertEquals($result->getData(), "hi"); + + $response = new ResponseCore(array(), false, 200); + $result = new BodyResult($response); + $this->assertTrue($result->isOK()); + $this->assertEquals($result->getData(), false); + + $response = new ResponseCore(array(), 0, 200); + $result = new BodyResult($response); + $this->assertTrue($result->isOK()); + $this->assertEquals($result->getData(), 0); + + $response = new ResponseCore(array(), "false", 200); + $result = new BodyResult($response); + $this->assertTrue($result->isOK()); + $this->assertEquals($result->getData(), "false"); } public function testParseInvalid404()