Completed
Push — master ( e600bd...21123c )
by Korotkov
02:11 queued 24s
created

ContainerResponseTrait::getJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
declare(strict_types = 1);
4
5
/**
6
 * @author    : Korotkov Danila <[email protected]>
7
 * @copyright Copyright (c) 2017, Korotkov Danila
8
 * @license   http://www.gnu.org/licenses/gpl.html GNU GPLv3.0
9
 */
10
11
namespace Rudra;
12
13
/**
14
 * Class ContainerResponseTrait
15
 *
16
 * @package Rudra
17
 */
18
trait ContainerResponseTrait
19
{
20
21
    /**
22
     * @param array $data
23
     */
24
    public function jsonResponse(array $data): void
25
    {
26
        header('Content-Type: application/json');
27
        echo $this->getJson($data);
28
    }
29
30
    /**
31
     * @param array $data
32
     *
33
     * @return string
34
     */
35
    protected function getJson(array $data): string
36
    {
37
        return json_encode($data);
38
    }
39
}
40