Passed
Pull Request — master (#10)
by Korotkov
01:41
created

ContainerResponseTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getJson() 0 3 1
A jsonResponse() 0 4 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\Traits;
12
13
/**
14
 * Class ContainerResponseTrait
15
 *
16
 * @package Rudra
17
 */
18
trait ContainerResponseTrait
19
{
20
21
    /**
22
     * @codeCoverageIgnore
23
     * @param array $data
24
     */
25
    public function jsonResponse(array $data): void
26
    {
27
        header('Content-Type: application/json');
28
        echo $this->getJson($data);
29
    }
30
31
    /**
32
     * @param array $data
33
     * @return string
34
     */
35
    protected function getJson(array $data): string
36
    {
37
        return json_encode($data);
38
    }
39
}
40