Skip to content

Commit

Permalink
Merge pull request #4 from DoclerLabs/fix-response-constructor-parame…
Browse files Browse the repository at this point in the history
…ters

Fixed constructor parameter order in Response
  • Loading branch information
mikemadisonweb committed Sep 7, 2020
2 parents de2deb7 + 2433b5d commit a26f9a4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [3.0.2] - 2020-09-07
### Fixed
- construct parameter order in `Response`

## [3.0.1] - 2020-09-03
### Fixed
- version in composer.json
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docler-labs/api-client-base",
"version": "3.0.1",
"version": "3.0.2",
"description": "SDK Generator - API Client Base",
"type": "library",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions src/Response/Handler/ResponseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public function handle(ResponseInterface $response): Response

if ($statusCode >= 200 && $statusCode < 300) {
if ($isResponseBodyEmpty) {
return new Response($statusCode, $headers);
return new Response($statusCode, null, $headers);
}

$decodedPayload = Json::decode($responseBody, true, 512, self::JSON_OPTIONS);

return new Response($statusCode, $headers, $decodedPayload);
return new Response($statusCode, $decodedPayload, $headers);
}

if ($statusCode === 400) {
Expand Down
16 changes: 8 additions & 8 deletions src/Response/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@ class Response
private $statusCode;

/** @var array */
private $headers;
private $payload;

/** @var array */
private $payload;
private $headers;

public function __construct(int $statusCode, array $headers = [], $payload = null)
public function __construct(int $statusCode, $payload = null, array $headers = [])
{
$this->statusCode = $statusCode;
$this->headers = $headers;
$this->payload = $payload;
$this->headers = $headers;
}

public function getStatusCode(): int
{
return $this->statusCode;
}

public function getHeaders(): array
public function getPayload()
{
return $this->headers;
return $this->payload;
}

public function getPayload()
public function getHeaders(): array
{
return $this->payload;
return $this->headers;
}
}
2 changes: 1 addition & 1 deletion test/suite/unit/Response/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testFilled()
{
$body = ['foo'];
$headers = ['bar'];
$responseData = new Response(2000, $headers, $body);
$responseData = new Response(2000, $body, $headers);

self::assertSame(2000, $responseData->getStatusCode());
self::assertSame($headers, $responseData->getHeaders());
Expand Down

0 comments on commit a26f9a4

Please sign in to comment.