@@ -110,27 +110,22 @@ private function dumpArray(array &$var, array $parents, int $level, int $column)
110
110
throw new Nette \InvalidStateException ('Nesting level too deep or recursive dependency. ' );
111
111
}
112
112
113
- $ space = str_repeat ($ this ->indentation , $ level );
114
- $ outInline = '' ;
115
- $ outWrapped = "\n$ space " ;
116
113
$ parents [] = $ var ;
117
114
$ hideKeys = is_int (($ keys = array_keys ($ var ))[0 ]) && $ keys === range ($ keys [0 ], $ keys [0 ] + count ($ var ) - 1 );
115
+ $ pairs = [];
118
116
119
117
foreach ($ var as $ k => &$ v ) {
120
118
$ keyPart = $ hideKeys && ($ k !== $ keys [0 ] || $ k === 0 )
121
119
? ''
122
120
: $ this ->dumpVar ($ k ) . ' => ' ;
123
- $ outInline .= ($ k === $ keys [0 ] ? '' : ', ' ) . $ keyPart ;
124
- $ outInline .= $ this ->dumpVar ($ v , $ parents , 0 , $ column + strlen ($ outInline ));
125
- $ outWrapped .= $ this ->indentation
126
- . $ keyPart
127
- . $ this ->dumpVar ($ v , $ parents , $ level + 1 , strlen ($ keyPart ))
128
- . ", \n$ space " ;
121
+ $ pairs [] = $ keyPart . $ this ->dumpVar ($ v , $ parents , $ level + 1 , strlen ($ keyPart ) + 1 ); // 1 = comma after item
129
122
}
130
123
131
- array_pop ($ parents );
132
- $ wrap = str_contains ($ outInline , "\n" ) || $ level * self ::IndentLength + $ column + strlen ($ outInline ) + 3 > $ this ->wrapLength ; // 3 = [],
133
- return '[ ' . ($ wrap ? $ outWrapped : $ outInline ) . '] ' ;
124
+ $ line = '[ ' . implode (', ' , $ pairs ) . '] ' ;
125
+ $ space = str_repeat ($ this ->indentation , $ level );
126
+ return !str_contains ($ line , "\n" ) && $ level * self ::IndentLength + $ column + strlen ($ line ) <= $ this ->wrapLength
127
+ ? $ line
128
+ : "[ \n$ space " . $ this ->indentation . implode (", \n$ space " . $ this ->indentation , $ pairs ) . ", \n$ space] " ;
134
129
}
135
130
136
131
@@ -263,21 +258,19 @@ public function format(string $statement, mixed ...$args): string
263
258
}
264
259
265
260
266
- /** @param mixed[] $var */
267
- private function dumpArguments (array & $ var , int $ column , bool $ named ): string
261
+ /** @param mixed[] $args */
262
+ private function dumpArguments (array $ args , int $ column , bool $ named ): string
268
263
{
269
- $ outInline = $ outWrapped = '' ;
270
-
271
- foreach ($ var as $ k => &$ v ) {
272
- $ k = !$ named || is_int ($ k ) ? '' : $ k . ': ' ;
273
- $ outInline .= $ outInline === '' ? '' : ', ' ;
274
- $ outInline .= $ k . $ this ->dumpVar ($ v , [$ var ], 0 , $ column + strlen ($ outInline ));
275
- $ outWrapped .= "\n" . $ this ->indentation . $ k . $ this ->dumpVar ($ v , [$ var ], 1 ) . ', ' ;
264
+ $ pairs = [];
265
+ foreach ($ args as $ k => $ v ) {
266
+ $ name = $ named && !is_int ($ k ) ? $ k . ': ' : '' ;
267
+ $ pairs [] = $ name . $ this ->dumpVar ($ v , [$ args ], 0 , $ column + strlen ($ name ) + 1 ); // 1 = ) after args
276
268
}
277
269
278
- return count ($ var ) > 1 && (str_contains ($ outInline , "\n" ) || $ column + strlen ($ outInline ) > $ this ->wrapLength )
279
- ? $ outWrapped . "\n"
280
- : $ outInline ;
270
+ $ line = implode (', ' , $ pairs );
271
+ return count ($ args ) < 2 || (!str_contains ($ line , "\n" ) && $ column + strlen ($ line ) <= $ this ->wrapLength )
272
+ ? $ line
273
+ : "\n" . $ this ->indentation . implode (", \n" . $ this ->indentation , $ pairs ) . ", \n" ;
281
274
}
282
275
283
276
0 commit comments