Completed
Push — master ( b5869e...077cc3 )
by Samuel
54s queued 49s
created

JsonApiResponse::send()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 8
cp 0
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Kelemen\ApiNette\Response;
4
5
use Nette\Utils\Json;
6
use Nette\Utils\JsonException;
7
8
class JsonApiResponse extends BaseApiResponse
9
{
10
    /** @var string|null */
11
    private $encodedData = null;
12
13
    /**
14
     * @param int $code
15
     * @param mixed $data
16
     * @param string $contentType
17
     * @param string $charset
18
     */
19 18
    public function __construct($code, $data = '', $contentType = 'application/json', $charset = 'utf-8')
20
    {
21 18
        parent::__construct($code, $data, $contentType, $charset);
22 18
    }
23
24
    /**
25
     * @return string
26
     * @throws JsonException
27
     */
28
    public function getEncodedData()
29
    {
30
        if ($this->encodedData === null) {
31
            $this->encodedData = Json::encode($this->data);
32
        }
33
        return $this->encodedData;
34
    }
35
}
36