Completed
Push — master ( f65d8f...4f3de5 )
by Pavel
04:14 queued 01:54
created

Renderer::jsonApiRender()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
nc 1
nop 3
dl 0
loc 14
rs 9.4285
c 1
b 0
f 0
1
<?php
2
namespace App\Common;
3
4
use Psr\Http\Message\ResponseInterface as Response;
5
6
final class Renderer
7
{
8
    /**
9
     * @param Response $response
10
     * @param int      $statusCode
11
     * @param string   $data
12
     *
13
     * @return Response
14
     */
15
    public function jsonApiRender(Response $response, $statusCode = 200, $data = '')
16
    {
17
        $jsonApiResponse = $response
18
            ->withHeader('Access-Control-Allow-Origin', '*')
19
            ->withHeader('Access-Control-Allow-Methods', 'GET, PUT, PATCH, POST, DELETE, OPTIONS')
20
            ->withHeader('Access-Control-Allow-Credentials', 'true')
21
            ->withHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Requested-With')
22
            ->withHeader('Content-Type', 'application/vnd.api+json')
23
            ->withStatus($statusCode);
24
25
        $jsonApiResponse->getBody()->write($data);
26
27
        return $jsonApiResponse;
28
    }
29
}