@@ -176,56 +176,59 @@ public function format(int $level = 1): array
176176 return [];
177177 }
178178
179- if (count ($ this ->children ) > 0 ) {
180- $ childStrings = [];
179+ if (count ($ this ->children ) === 0 ) {
180+ $ strings [] = sprintf (
181+ '%s%s%s: %s, ' ,
182+ $ padding ,
183+ $ this ->name ,
184+ ($ this ->optional ) ? '? ' : '' ,
185+ $ this ->type
186+ );
181187
182- foreach ($ this ->children as $ child ) {
183- $ childStrings = array_merge ($ childStrings , $ child ->format ($ level + 1 ));
184- }
188+ return $ strings ;
189+ }
185190
186- if (count ($ childStrings ) === 0 ) {
187- return [];
188- }
191+ $ childStrings = [];
189192
190- if ($ this ->isArrayShape ()) {
191- if ($ this ->name !== null ) {
192- $ strings [] = sprintf (
193- '%s%s%s: %s{ ' ,
194- $ padding ,
195- $ this ->name ,
196- ($ this ->optional ) ? '? ' : '' ,
197- $ this ->type
198- );
199- }
200- } else {
201- $ strings [] = sprintf (
202- '%s%s%s: array<int|string, %s{ ' ,
203- $ padding ,
204- $ this ->name ,
205- ($ this ->optional ) ? '? ' : '' ,
206- $ this ->type
207- );
208- }
193+ foreach ($ this ->children as $ child ) {
194+ $ childStrings = array_merge ($ childStrings , $ child ->format ($ level + 1 ));
195+ }
209196
210- $ strings = array_merge ($ strings , $ childStrings );
197+ if (count ($ childStrings ) === 0 ) {
198+ return [];
199+ }
211200
212- if ($ this ->isArrayShape ()) {
213- if ($ this ->name !== null ) {
214- $ strings [] = "$ padding}, " ;
215- }
216- } else {
217- $ strings [] = "$ padding}>, " ;
201+ if ($ this ->isArrayShape ()) {
202+ if ($ this ->name === null ) {
203+ $ strings = array_merge ($ strings , $ childStrings );
204+
205+ return $ strings ;
218206 }
219- } else {
207+
220208 $ strings [] = sprintf (
221- '%s%s%s: %s, ' ,
209+ '%s%s%s: %s{ ' ,
222210 $ padding ,
223211 $ this ->name ,
224212 ($ this ->optional ) ? '? ' : '' ,
225213 $ this ->type
226214 );
215+ $ strings = array_merge ($ strings , $ childStrings );
216+ $ strings [] = sprintf ('%s}, ' , $ padding );
217+
218+ return $ strings ;
227219 }
228220
221+ // Not an array with a shape
222+ $ strings [] = sprintf (
223+ '%s%s%s: array<int|string, %s{ ' ,
224+ $ padding ,
225+ $ this ->name ,
226+ ($ this ->optional ) ? '? ' : '' ,
227+ $ this ->type
228+ );
229+ $ strings = array_merge ($ strings , $ childStrings );
230+ $ strings [] = sprintf ('%s}>, ' , $ padding );
231+
229232 return $ strings ;
230233 }
231234}
0 commit comments