Issues (12)

src/Application/Responder/JsonResponder.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace App\Application\Responder;
4
5
use Psr\Http\Message\ResponseInterface;
6
7
final readonly class JsonResponder
0 ignored issues
show
A parse error occurred: Syntax error, unexpected T_READONLY, expecting T_CLASS on line 7 at column 6
Loading history...
8
{
9
    /**
10
     * Write JSON to the response body.
11
     *
12
     * @param ResponseInterface $response The response
13
     * @param mixed $data The data
14
     * @param int $status
15
     *
16
     * @return ResponseInterface The response
17
     */
18 10
    public function encodeAndAddToResponse(
19
        ResponseInterface $response,
20
        mixed $data = null,
21
        int $status = 200
22
    ): ResponseInterface {
23 10
        $response->getBody()->write((string)json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR));
24 10
        $response = $response->withStatus($status);
25
26 10
        return $response->withHeader('Content-Type', 'application/json');
27
    }
28
}
29