Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
fix decoding null values that generate issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mavimo committed Feb 14, 2019
1 parent 1059856 commit b4f84d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/LooplineSystems/CloseIoApiWrapper/CloseIoResponse.php
Expand Up @@ -134,6 +134,12 @@ public function getHeaders(): array
*/
private function decodeBody(): void
{
if (empty($this->body) || $this->body === null) {
$this->decodedBody = [];

return;
}

$this->decodedBody = json_decode($this->body, true);

if (json_last_error() !== JSON_ERROR_NONE) {
Expand Down
Expand Up @@ -35,7 +35,7 @@ public function testGetters(): void
/**
* @dataProvider getDecodedBodyDataProvider
*/
public function testGetDecodedBody(string $body, array $expectedDecodedBody): void
public function testGetDecodedBody(?string $body, array $expectedDecodedBody): void
{
$response = new CloseIoResponse(new CloseIoRequest('GET', '/foo/'), 200, $body);

Expand All @@ -47,6 +47,8 @@ public function getDecodedBodyDataProvider(): array
return [
['{"foo":"bar"}', ['foo' => 'bar']],
['false', []],
['', []],
[null, []],
];
}

Expand Down

0 comments on commit b4f84d6

Please sign in to comment.