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

JsonApiResponse::getEncodedData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 6
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