Skip to content

Commit

Permalink
Change the signature of the constructor (internal class)
Browse files Browse the repository at this point in the history
Make it more user-friendly
  • Loading branch information
mnapoli committed Jan 28, 2020
1 parent 0e33d14 commit 907a27c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Event/Http/FpmHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function handleRequest(HttpRequestEvent $event, Context $context): HttpRe
unset($responseHeaders['status']);
}

$response = new HttpResponse($status ?? 200, $responseHeaders, $response->getBody());
$response = new HttpResponse($response->getBody(), $responseHeaders, $status ?? 200);

$this->ensureStillRunning();

Expand Down
8 changes: 4 additions & 4 deletions src/Event/Http/HttpResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ final class HttpResponse
/** @var string */
private $body;

public function __construct(int $statusCode, array $headers, string $body)
public function __construct(string $body, array $headers, int $statusCode = 200)
{
$this->statusCode = $statusCode;
$this->headers = $headers;
$this->body = $body;
$this->headers = $headers;
$this->statusCode = $statusCode;
}

public static function fromPsr7Response(ResponseInterface $response): self
Expand All @@ -44,7 +44,7 @@ public static function fromPsr7Response(ResponseInterface $response): self
$response->getBody()->rewind();
$body = $response->getBody()->getContents();

return new self($response->getStatusCode(), $headers, $body);
return new self($body, $headers, $response->getStatusCode());
}

public function toApiGatewayFormat(bool $multiHeaders = false): array
Expand Down
5 changes: 2 additions & 3 deletions tests/Event/Http/HttpResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ class HttpResponseTest extends TestCase
public function test conversion to API Gateway format()
{
$response = new HttpResponse(
200,
'<p>Hello world!</p>',
[
'Content-Type' => 'text/html; charset=utf-8',
],
'<p>Hello world!</p>'
]
);
self::assertSame([
'isBase64Encoded' => false,
Expand Down

0 comments on commit 907a27c

Please sign in to comment.