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

JsonApiResponse::getCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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