Completed
Push — master ( eebc54...730195 )
by Afshin
03:20
created

JsonHandler   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 19
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A render() 0 6 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: afshin
5
 * Date: 12/18/17
6
 * Time: 8:28 PM
7
 */
8
9
namespace Core\Handlers;
10
11
use \Psr\Http\Message\ResponseInterface;
12
13
14
class JsonHandler
15
{
16
    /**
17
     *
18
     * @param ResponseInterface $response
19
     * @param int $statusCode
20
     * @param array $data
21
     *
22
     * @return ResponseInterface
23
     *
24
     * @throws \InvalidArgumentException
25
     * @throws \RuntimeException
26
     */
27
    public function render(ResponseInterface $response, $statusCode = 200, array $data = [])
28
    {
29
        $newResponse = $response->withHeader('Content-Type', 'application/json');
30
        $newResponse = $newResponse->withStatus($statusCode);
31
        $newResponse->getBody()->write(json_encode($data));
32
        return $newResponse;
33
    }
34
}
35
36
37
38