Completed
Push — master ( 7bd75b...613007 )
by Robert
05:22
created

JsonResponse::getCallback()   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 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace MediaMonks\RestApiBundle\Response;
4
5
use Symfony\Component\HttpFoundation\JsonResponse as BaseJsonResponse;
6
7
class JsonResponse extends BaseJsonResponse
8
{
9
    /**
10
     * Constructor.
11
     *
12
     * @param mixed $data The response data
13
     * @param int $status The response status code
14
     * @param array $headers An array of response headers
15
     */
16 23
    public function __construct($data = null, $status = 200, $headers = [])
17
    {
18 23
        parent::__construct('', $status, $headers);
19
20 23
        if (null === $data) {
21 2
            $data = new \ArrayObject();
22 2
        }
23
24 23
        $this->setContent($data);
25 23
    }
26
27
    /**
28
     * We need this because setData() does json encoding already and
29
     * this messes up the jsonp callback.
30
     * It is a performance hit to let is decode/encode a second time
31
     *
32
     * @param mixed $content
33
     * @return $this
34
     */
35 23
    public function setContent($content)
36
    {
37 23
        $this->data = $this->content = $content;
38 23
        return $this;
39
    }
40
41
    /**
42
     * @return mixed
43
     */
44 1
    public function getCallback()
45
    {
46 1
        return $this->callback;
47
    }
48
}
49