Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
parsilver committed May 15, 2023
1 parent 41b8e6c commit 1b2bb51
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Response implements ResponseInterface
protected $jsonDecoded;

/**
* @var string
* @var string|null
*/
protected $content;

Expand All @@ -26,7 +26,7 @@ public function __construct(
protected PsrRequestInterface $request,
protected PsrResponseInterface $response
) {
$this->content = $this->response->getBody()->getContents();
//
}

/**
Expand All @@ -42,6 +42,10 @@ public function statusCode(): int
*/
public function body(): string
{
if (is_null($this->content)) {
$this->content = $this->response->getBody()->getContents();
}

return $this->content;
}

Expand Down Expand Up @@ -69,7 +73,7 @@ public function isSuccessfull(): bool
public function json(?string $key = null): mixed
{
if (is_null($this->jsonDecoded)) {
$this->jsonDecoded = @json_decode($this->content, true) ?: false;
$this->jsonDecoded = @json_decode($this->body(), true) ?: false;
}

if ($this->jsonDecoded === false) {
Expand Down
2 changes: 1 addition & 1 deletion tests/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
it('should return the psr response', function () {
$response = new Response(
\Mockery::mock(PsrRequestInterface::class),
\Mockery::mock(PsrResponseInterface::class)
\Mockery::mock(PsrResponseInterface::class),
);

expect($response->getPsrResponse())->toBeInstanceOf(PsrResponseInterface::class);
Expand Down

0 comments on commit 1b2bb51

Please sign in to comment.