1 | <?php |
||
20 | abstract class JsonReader implements JsonReadable |
||
21 | { |
||
22 | /** |
||
23 | * A stack representing the next element to be consumed |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $stack = []; |
||
28 | |||
29 | /** |
||
30 | * An array of types that map to the position in the stack |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $stackTypes = []; |
||
35 | |||
36 | /** |
||
37 | * The current size of the stack |
||
38 | * |
||
39 | * @var int |
||
40 | */ |
||
41 | protected $stackSize = 0; |
||
42 | |||
43 | /** |
||
44 | * An array of path names that correspond to the current stack |
||
45 | * |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $pathNames = []; |
||
49 | |||
50 | /** |
||
51 | * An array of path indicies that correspond to the current stack. This array could contain invalid |
||
52 | * values at indexes outside the current stack. It could also contain incorrect values at indexes |
||
53 | * where a path name is used. Data should only be fetched by referencing the current position in the stack. |
||
54 | * |
||
55 | * @var array |
||
56 | */ |
||
57 | protected $pathIndices = []; |
||
58 | |||
59 | /** |
||
60 | * A cache of the current [@see JsonToken]. This should get nulled out |
||
61 | * whenever a new token should be returned with the subsequent call |
||
62 | * to [@see JsonDecodeReader::peek] |
||
63 | * |
||
64 | * @var |
||
65 | */ |
||
66 | protected $currentToken; |
||
67 | |||
68 | /** |
||
69 | * Returns an enum representing the type of the next token without consuming it |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | abstract public function peek(): string; |
||
74 | |||
75 | /** |
||
76 | * Get the current read path in json xpath format |
||
77 | * |
||
78 | * @return string |
||
79 | */ |
||
80 | abstract public function getPath(): string; |
||
81 | |||
82 | /** |
||
83 | * Push an element onto the stack |
||
84 | * |
||
85 | * @param JsonElement|Iterator $element |
||
86 | * @param string $type |
||
|
|||
87 | */ |
||
88 | abstract protected function push($element, $type = null): void; |
||
89 | |||
90 | /** |
||
91 | * Consumes the next token and asserts it's the end of an array |
||
92 | * |
||
93 | * @return void |
||
94 | * @throws \Tebru\Gson\Exception\UnexpectedJsonTokenException If the next token is not END_ARRAY |
||
95 | */ |
||
96 | 13 | public function endArray(): void |
|
103 | |||
104 | /** |
||
105 | * Consumes the next token and asserts it's the end of an object |
||
106 | * |
||
107 | * @return void |
||
108 | * @throws \Tebru\Gson\Exception\UnexpectedJsonTokenException If the next token is not END_OBJECT |
||
109 | */ |
||
110 | 11 | public function endObject(): void |
|
117 | |||
118 | /** |
||
119 | * Returns true if the array or object has another element |
||
120 | * |
||
121 | * If the current scope is not an array or object, this returns false |
||
122 | * |
||
123 | * @return bool |
||
124 | */ |
||
125 | 10 | public function hasNext(): bool |
|
131 | |||
132 | /** |
||
133 | * Consumes the next name and returns it |
||
134 | * |
||
135 | * @return string |
||
136 | * @throws \Tebru\Gson\Exception\UnexpectedJsonTokenException If the next token is not NAME |
||
137 | */ |
||
138 | 25 | public function nextName(): string |
|
154 | |||
155 | /** |
||
156 | * Consumes the value of the next token and asserts it's null |
||
157 | * |
||
158 | * @return null |
||
159 | * @throws \Tebru\Gson\Exception\UnexpectedJsonTokenException If the next token is not NAME or NULL |
||
160 | */ |
||
161 | 4 | public function nextNull() |
|
171 | |||
172 | /** |
||
173 | * Skip the next value. If the next value is an object or array, all children will |
||
174 | * also be skipped. |
||
175 | * |
||
176 | * @return void |
||
177 | */ |
||
178 | 2 | public function skipValue(): void |
|
182 | |||
183 | /** |
||
184 | * Pop the last element off the stack and return it |
||
185 | * |
||
186 | * @return JsonElement|Iterator|mixed |
||
187 | */ |
||
188 | 105 | protected function pop() |
|
196 | |||
197 | /** |
||
198 | * Check that the next token equals the expectation |
||
199 | * |
||
200 | * @param string $expectedToken |
||
201 | * @throws \Tebru\Gson\Exception\UnexpectedJsonTokenException If the next token is not the expectation |
||
202 | */ |
||
203 | 116 | protected function expect(string $expectedToken) |
|
217 | |||
218 | /** |
||
219 | * Increment the path index. This should be called any time a new value is parsed. |
||
220 | */ |
||
221 | 81 | protected function incrementPathIndex(): void |
|
231 | } |
||
232 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.