@@ -90,19 +90,12 @@ private function writeNode(NodeInterface $node, ?NodeInterface $parentNode = nul
90
90
$ children = $ this ->getPrototypeChildren ($ node );
91
91
}
92
92
93
- if (!$ children ) {
94
- if ($ node ->hasDefaultValue () && \count ($ defaultArray = $ node ->getDefaultValue ())) {
95
- $ default = '' ;
96
- } elseif (!\is_array ($ example )) {
97
- $ default = '[] ' ;
98
- }
93
+ if (!$ children && !($ node ->hasDefaultValue () && \count ($ defaultArray = $ node ->getDefaultValue ()))) {
94
+ $ default = '[] ' ;
99
95
}
100
96
} elseif ($ node instanceof EnumNode) {
101
97
$ comments [] = 'One of ' .implode ('; ' , array_map ('json_encode ' , $ node ->getValues ()));
102
98
$ default = $ node ->hasDefaultValue () ? Inline::dump ($ node ->getDefaultValue ()) : '~ ' ;
103
- } elseif (VariableNode::class === \get_class ($ node ) && \is_array ($ example )) {
104
- // If there is an array example, we are sure we dont need to print a default value
105
- $ default = '' ;
106
99
} else {
107
100
$ default = '~ ' ;
108
101
@@ -170,7 +163,7 @@ private function writeNode(NodeInterface $node, ?NodeInterface $parentNode = nul
170
163
171
164
$ this ->writeLine ('# ' .$ message .': ' , $ depth * 4 + 4 );
172
165
173
- $ this ->writeArray (array_map ([Inline::class, 'dump ' ], $ example ), $ depth + 1 );
166
+ $ this ->writeArray (array_map ([Inline::class, 'dump ' ], $ example ), $ depth + 1 , true );
174
167
}
175
168
176
169
if ($ children ) {
@@ -191,7 +184,7 @@ private function writeLine(string $text, int $indent = 0)
191
184
$ this ->reference .= sprintf ($ format , $ text )."\n" ;
192
185
}
193
186
194
- private function writeArray (array $ array , int $ depth )
187
+ private function writeArray (array $ array , int $ depth, bool $ asComment = false )
195
188
{
196
189
$ isIndexed = array_values ($ array ) === $ array ;
197
190
@@ -202,14 +195,16 @@ private function writeArray(array $array, int $depth)
202
195
$ val = $ value ;
203
196
}
204
197
198
+ $ prefix = $ asComment ? '# ' : '' ;
199
+
205
200
if ($ isIndexed ) {
206
- $ this ->writeLine ('- ' .$ val , $ depth * 4 );
201
+ $ this ->writeLine ($ prefix . '- ' .$ val , $ depth * 4 );
207
202
} else {
208
- $ this ->writeLine (sprintf ('%-20s %s ' , $ key .': ' , $ val ), $ depth * 4 );
203
+ $ this ->writeLine (sprintf ('%s% -20s %s ' , $ prefix , $ key .': ' , $ val ), $ depth * 4 );
209
204
}
210
205
211
206
if (\is_array ($ value )) {
212
- $ this ->writeArray ($ value , $ depth + 1 );
207
+ $ this ->writeArray ($ value , $ depth + 1 , $ asComment );
213
208
}
214
209
}
215
210
}
0 commit comments