| Conditions | 3 |
| Paths | 4 |
| Total Lines | 17 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 32 | 63 | public function buildJsonResponse(ResponseInterface $response): ResponseInterface |
|
| 33 | { |
||
| 34 | 63 | $this->headers['content-type'] = 'application/json'; |
|
| 35 | |||
| 36 | 63 | foreach ($this->headers as $key => $value) { |
|
| 37 | /** @var ResponseInterface $response */ |
||
| 38 | 63 | $response = $response->withAddedHeader($key, $value); |
|
| 39 | } |
||
| 40 | |||
| 41 | 63 | if ($response->getBody()->isWritable()) { |
|
| 42 | 63 | $response->getBody()->write(json_encode([ |
|
| 43 | 63 | 'status_code' => $this->status, |
|
| 44 | 63 | 'reason_phrase' => $this->message |
|
| 45 | 63 | ])); |
|
| 46 | } |
||
| 47 | |||
| 48 | 63 | return $response->withStatus($this->status, $this->message); |
|
| 49 | } |
||
| 51 |