Total Complexity | 8 |
Total Lines | 35 |
Duplicated Lines | 0 % |
Coverage | 76.92% |
Changes | 0 |
1 | <?php |
||
8 | class JSONType implements Type |
||
9 | { |
||
10 | /** |
||
11 | * @var int options for json_encode() |
||
12 | * |
||
13 | * @see json_encode() |
||
14 | */ |
||
15 | public $json_encode_options = JSON_UNESCAPED_UNICODE; |
||
16 | |||
17 | 1 | public function convertToSQL($value) |
|
18 | { |
||
19 | 1 | if ($value === null || $value === '') { |
|
20 | return null; |
||
21 | } |
||
22 | |||
23 | 1 | $json = json_encode($value, $this->json_encode_options); |
|
24 | |||
25 | 1 | if ($json === false) { |
|
26 | 1 | throw new RuntimeException(json_last_error_msg()); |
|
27 | } |
||
28 | |||
29 | 1 | return $json; |
|
30 | } |
||
31 | |||
32 | 1 | public function convertToPHP($value) |
|
43 | } |
||
44 | } |
||
45 |