Total Complexity | 6 |
Total Lines | 33 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
13 | class JavascriptUtils { |
||
14 | |||
15 | /** |
||
16 | * Returns a JSON string from an object. |
||
17 | * |
||
18 | * @param mixed $object |
||
19 | * @return string |
||
20 | */ |
||
21 | public static function toJSON($object): string { |
||
22 | if (\is_object($object)) { |
||
23 | if (\method_exists($object, 'toArray')) { |
||
24 | $object = $object->toArray(); |
||
25 | } else { |
||
26 | $object = (array) $object; |
||
27 | } |
||
28 | } |
||
29 | return \json_encode($object, \JSON_PRETTY_PRINT | \JSON_NUMERIC_CHECK); |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * Add script tags to a javascript code. |
||
34 | * |
||
35 | * @param string $script |
||
36 | * @return string |
||
37 | */ |
||
38 | public static function wrapScript(string $script): string { |
||
46 | } |
||
47 | } |
||
49 |