@@ -130,7 +130,7 @@ public function toFile(array $values): string
130130 }
131131
132132 /**
133- * @param array<array-key, mixed > $items
133+ * @param array<array-key, scalar|scalar[] > $items
134134 */
135135 public function recursiveToFile (
136136 array $ items ,
@@ -140,24 +140,29 @@ public function recursiveToFile(
140140 $ output = '' ;
141141
142142 foreach ($ items as $ key => $ value ) {
143+
144+ if (is_string ($ key )) {
145+ $ key = str_replace ('\" ' , '" ' , addslashes ($ key ));
146+ }
147+
143148 if (is_array ($ value )) {
144149 $ value = $ this ->recursiveToFile ($ value , $ prefix .' ' );
145150
146151 if (is_string ($ key )) {
147- $ key = str_replace ('\" ' , '" ' , addslashes ($ key ));
148-
149152 $ output .= "\n{$ prefix } ' {$ key }' => [ {$ value }\n {$ prefix }], " ;
150153 } else {
151154 $ output .= "\n{$ prefix } [ {$ value }\n {$ prefix }], " ;
152155 }
153156 } else {
154- $ value = str_replace ('\" ' , '" ' , addslashes ($ value ));
157+
158+ if (is_string ($ value )) {
159+ $ value = "' " .str_replace ('\" ' , '" ' , addslashes ($ value ))."' " ;
160+ }
155161
156162 if (is_string ($ key )) {
157- $ key = str_replace ('\" ' , '" ' , addslashes ($ key ));
158- $ output .= "\n{$ prefix } ' {$ key }' => ' {$ value }', " ;
163+ $ output .= "\n{$ prefix } ' {$ key }' => {$ value }, " ;
159164 } else {
160- $ output .= "\n{$ prefix } ' {$ value }' , " ;
165+ $ output .= "\n{$ prefix } {$ value }, " ;
161166 }
162167 }
163168 }
0 commit comments