JSONP   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 16
ccs 8
cts 8
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A respond() 0 9 2
A translateAndRespond() 0 3 1
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