File tree Expand file tree Collapse file tree 1 file changed +27
-5
lines changed Expand file tree Collapse file tree 1 file changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -329,16 +329,38 @@ public function getParamExample(array $param): string
329
329
* @return string
330
330
* @var $data array
331
331
*/
332
- protected function jsonToHash (array $ data ): string
332
+ protected function jsonToHash (array $ data, int $ indent = 0 ): string
333
333
{
334
- $ output = '{ ' ;
334
+ if (empty ($ data )) {
335
+ return '{} ' ;
336
+ }
335
337
338
+ $ output = "{ \n" ;
339
+ $ indentStr = str_repeat (' ' , $ indent + 4 );
340
+ $ keys = array_keys ($ data );
341
+
336
342
foreach ($ data as $ key => $ node ) {
337
- $ value = (is_array ($ node )) ? $ this ->jsonToHash ($ node ) : $ node ;
338
- $ output .= '" ' . $ key . '" => ' . ((is_string ($ node )) ? '" ' . $ value . '" ' : $ value ) . (($ key !== array_key_last ($ data )) ? ', ' : '' );
343
+ if (is_array ($ node )) {
344
+ $ value = $ this ->jsonToHash ($ node , $ indent + 1 );
345
+ } elseif (is_bool ($ node )) {
346
+ $ value = $ node ? 'true ' : 'false ' ;
347
+ } elseif (is_string ($ node )) {
348
+ $ value = '" ' . $ node . '" ' ;
349
+ } else {
350
+ $ value = $ node ;
351
+ }
352
+
353
+ $ output .= $ indentStr . '" ' . $ key . '" => ' . $ value ;
354
+
355
+ // Add comma if not the last item
356
+ if ($ key !== end ($ keys )) {
357
+ $ output .= ', ' ;
358
+ }
359
+
360
+ $ output .= "\n" ;
339
361
}
340
362
341
- $ output .= '} ' ;
363
+ $ output .= str_repeat ( ' ' , $ indent + 2 ) . '} ' ;
342
364
343
365
return $ output ;
344
366
}
You can’t perform that action at this time.
0 commit comments