Skip to content

Commit 00749fa

Browse files
authored
Separate chain calls (#63)
1 parent e2f007f commit 00749fa

11 files changed

+599
-175
lines changed

README.md

+12-4
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,13 @@ use Yiisoft\DataResponse\DataResponseFactory;
4848

4949
$factory = new DataResponseFactory($responseFactory);
5050
$dataResponse = $factory->createResponse('test');
51-
$dataResponse->getBody()->rewind();
51+
$dataResponse
52+
->getBody()
53+
->rewind();
5254

53-
echo $dataResponse->getBody()->getContents(); // "test"
55+
echo $dataResponse
56+
->getBody()
57+
->getContents(); // "test"
5458
```
5559

5660
### Formatters
@@ -68,10 +72,14 @@ use Yiisoft\DataResponse\Formatter\JsonDataResponseFormatter;
6872
$factory = new DataResponseFactory($responseFactory);
6973
$dataResponse = $factory->createResponse('test');
7074
$dataResponse = $dataResponse->withResponseFormatter(new JsonDataResponseFormatter());
71-
$dataResponse->getBody()->rewind();
75+
$dataResponse
76+
->getBody()
77+
->rewind();
7278

7379
echo $dataResponse->getHeader('Content-Type'); // ["application/json; charset=UTF-8"]
74-
echo $dataResponse->getBody()->getContents(); // "test"
80+
echo $dataResponse
81+
->getBody()
82+
->getContents(); // "test"
7583
```
7684

7785
The following formatters are available:

src/DataResponse.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ public function getBody(): StreamInterface
8383

8484
if (is_string($data)) {
8585
$this->clearResponseBody();
86-
$this->response->getBody()->write($data);
86+
$this->response
87+
->getBody()
88+
->write($data);
8789
return $this->dataStream = $this->response->getBody();
8890
}
8991

src/ResponseContentTrait.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public function withEncoding(string $encoding): self
5151
private function addToResponse(ResponseInterface $response, ?string $content = null): ResponseInterface
5252
{
5353
if ($content !== null) {
54-
$response->getBody()->write($content);
54+
$response
55+
->getBody()
56+
->write($content);
5557
}
5658

5759
return $response->withHeader(Header::CONTENT_TYPE, "$this->contentType; charset=$this->encoding");

tests/DataResponseFactoryTest.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ final class DataResponseFactoryTest extends TestCase
1212
{
1313
public function testCreateResponseWithDefaultParams(): void
1414
{
15-
$response = $this->createDataResponseFactory()->createResponse();
15+
$response = $this
16+
->createDataResponseFactory()
17+
->createResponse();
1618

1719
$this->assertInstanceOf(ResponseInterface::class, $response);
1820
$this->assertInstanceOf(DataResponse::class, $response);
@@ -24,7 +26,9 @@ public function testCreateResponseWithDefaultParams(): void
2426

2527
public function testCreateResponseWithCustomParams(): void
2628
{
27-
$response = $this->createDataResponseFactory()->createResponse(['key' => 'value'], Status::BAD_REQUEST, 'reason');
29+
$response = $this
30+
->createDataResponseFactory()
31+
->createResponse(['key' => 'value'], Status::BAD_REQUEST, 'reason');
2832

2933
$this->assertInstanceOf(ResponseInterface::class, $response);
3034
$this->assertInstanceOf(DataResponse::class, $response);

0 commit comments

Comments
 (0)