JSONP::respond()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 2
rs 10
1
<?php
2
/**
3
 * This file is part of the Divergence package.
4
 *
5
 * (c) Henry Paradiz <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Divergence\Helpers;
12
13
/**
14
 * JSONP
15
 *
16
 * @package Divergence
17
 * @author Henry Paradiz <[email protected]>
18
 */
19
class JSONP
20
{
21 2
    public static function respond($data)
22
    {
23 2
        $JSON = json_encode($data, \JSON_UNESCAPED_UNICODE | \JSON_HEX_TAG);
24
25 2
        if (!$JSON) {
26 1
            throw new \Exception(json_last_error_msg());
27
        }
28 2
        header('Content-type: application/javascript; charset=utf-8', true);
29 2
        echo 'var data = ' . $JSON;
30
    }
31
32 1
    public static function translateAndRespond($data)
33
    {
34 1
        static::respond(JSON::translateObjects($data));
35
    }
36
}
37