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

ContainerResponseTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 22
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonResponse() 0 5 1
A getJson() 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;
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