1 | <?php declare(strict_types=1); |
||
13 | class JsonSerializer |
||
14 | { |
||
15 | /** |
||
16 | * Populates the actual value into a JSON field, i.e. it has reached the end of the line and no |
||
17 | * further nesting is required. |
||
18 | * |
||
19 | * @param Parameter $param The schema that defines how the JSON field is being populated |
||
20 | * @param mixed $userValue The user value that is populating a JSON field |
||
21 | * @param array $json The existing JSON structure that will be populated |
||
22 | * |
||
23 | * @return array|mixed |
||
24 | */ |
||
25 | 70 | private function stockValue(Parameter $param, $userValue, array $json): array |
|
40 | |||
41 | /** |
||
42 | * Populates a value into an array-like structure. |
||
43 | * |
||
44 | * @param Parameter $param The schema that defines how the JSON field is being populated |
||
45 | * @param mixed $userValue The user value that is populating a JSON field |
||
46 | * |
||
47 | * @return array|mixed |
||
48 | */ |
||
49 | 12 | private function stockArrayJson(Parameter $param, array $userValue): array |
|
57 | |||
58 | /** |
||
59 | * Populates a value into an object-like structure. |
||
60 | * |
||
61 | * @param Parameter $param The schema that defines how the JSON field is being populated |
||
62 | * @param mixed $userValue The user value that is populating a JSON field |
||
63 | * |
||
64 | * @return array |
||
65 | */ |
||
66 | 21 | private function stockObjectJson(Parameter $param, \stdClass $userValue): array |
|
74 | |||
75 | /** |
||
76 | * A generic method that will populate a JSON structure with a value according to a schema. It |
||
77 | * supports multiple types and will delegate accordingly. |
||
78 | * |
||
79 | * @param Parameter $param The schema that defines how the JSON field is being populated |
||
80 | * @param mixed $userValue The user value that is populating a JSON field |
||
81 | * @param array $json The existing JSON structure that will be populated |
||
82 | * |
||
83 | * @return array |
||
84 | */ |
||
85 | 70 | public function stockJson(Parameter $param, $userValue, array $json): array |
|
95 | |||
96 | private function serializeObjectValue($value) |
||
111 | } |
||
112 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: