@@ -185,23 +185,9 @@ public function next()
185
185
private function processStack (\Generator $ generator , $ isObject )
186
186
{
187
187
if ($ isObject ) {
188
- $ key = $ generator ->key ();
189
-
190
- if (!is_int ($ key ) && !is_string ($ key )) {
191
- $ this ->addError ('Only string or integer keys are supported ' );
188
+ if (!$ this ->processKey ($ generator ->key ())) {
192
189
return ;
193
190
}
194
-
195
- if (!$ this ->first ) {
196
- $ this ->outputLine (', ' , JsonToken::T_COMMA );
197
- }
198
-
199
- $ this ->outputJson ((string ) $ key , JsonToken::T_NAME );
200
- $ this ->output (': ' , JsonToken::T_COLON );
201
-
202
- if ($ this ->options & JSON_PRETTY_PRINT ) {
203
- $ this ->output (' ' , JsonToken::T_WHITESPACE );
204
- }
205
191
} elseif (!$ this ->first ) {
206
192
$ this ->outputLine (', ' , JsonToken::T_COMMA );
207
193
}
@@ -210,6 +196,32 @@ private function processStack(\Generator $generator, $isObject)
210
196
$ this ->processValue ($ generator ->current ());
211
197
}
212
198
199
+ /**
200
+ * Handles the given value key into JSON.
201
+ * @param mixed $key The key to process
202
+ * @return bool True if the key is valid, false if not
203
+ */
204
+ private function processKey ($ key )
205
+ {
206
+ if (!is_int ($ key ) && !is_string ($ key )) {
207
+ $ this ->addError ('Only string or integer keys are supported ' );
208
+ return false ;
209
+ }
210
+
211
+ if (!$ this ->first ) {
212
+ $ this ->outputLine (', ' , JsonToken::T_COMMA );
213
+ }
214
+
215
+ $ this ->outputJson ((string ) $ key , JsonToken::T_NAME );
216
+ $ this ->output (': ' , JsonToken::T_COLON );
217
+
218
+ if ($ this ->options & JSON_PRETTY_PRINT ) {
219
+ $ this ->output (' ' , JsonToken::T_WHITESPACE );
220
+ }
221
+
222
+ return true ;
223
+ }
224
+
213
225
/**
214
226
* Handles the given JSON value appropriately depending on it's type.
215
227
* @param mixed $value The value that should be encoded as JSON
0 commit comments