Total Complexity | 10 |
Total Lines | 77 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
10 | final class JSONScalarType extends ScalarType |
||
11 | { |
||
12 | public const NAME = 'JSON'; |
||
13 | |||
14 | /** |
||
15 | * @var self |
||
16 | */ |
||
17 | private static $instance; |
||
18 | |||
19 | public function __construct() |
||
20 | { |
||
21 | parent::__construct([ |
||
22 | 'name' => 'JSON', |
||
23 | 'description' => 'A GraphQL type that can contain json' |
||
24 | ]); |
||
25 | } |
||
26 | |||
27 | public static function getInstance(): self |
||
28 | { |
||
29 | if (self::$instance === null) { |
||
30 | self::$instance = new self(); |
||
31 | } |
||
32 | return self::$instance; |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * @param mixed $value |
||
37 | * @return mixed |
||
38 | */ |
||
39 | public function serialize($value) |
||
40 | { |
||
41 | return $value; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @param mixed $value |
||
46 | * @return mixed |
||
47 | * @throws Error |
||
48 | */ |
||
49 | public function parseValue($value) |
||
50 | { |
||
51 | return $this->decodeJSON($value); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @param mixed $valueNode |
||
56 | * @param mixed[]|null $variables |
||
57 | * @return mixed |
||
58 | * @throws Exception |
||
59 | */ |
||
60 | public function parseLiteral($valueNode, ?array $variables = null) |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * |
||
73 | * @param mixed $value |
||
74 | * @throws Error |
||
75 | * @return mixed |
||
76 | */ |
||
77 | private function decodeJSON($value) |
||
87 | } |
||
88 | } |
||
89 |