18
18
use Symfony \Component \Config \Definition \NodeInterface ;
19
19
use Symfony \Component \Config \Definition \PrototypedArrayNode ;
20
20
use Symfony \Component \Config \Definition \ScalarNode ;
21
- use Symfony \Component \Config \Definition \VariableNode ;
22
21
use Symfony \Component \Yaml \Inline ;
23
22
24
23
/**
@@ -90,19 +89,12 @@ private function writeNode(NodeInterface $node, ?NodeInterface $parentNode = nul
90
89
$ children = $ this ->getPrototypeChildren ($ node );
91
90
}
92
91
93
- if (!$ children ) {
94
- if ($ node ->hasDefaultValue () && \count ($ defaultArray = $ node ->getDefaultValue ())) {
95
- $ default = '' ;
96
- } elseif (!\is_array ($ example )) {
97
- $ default = '[] ' ;
98
- }
92
+ if (!$ children && !($ node ->hasDefaultValue () && \count ($ defaultArray = $ node ->getDefaultValue ()))) {
93
+ $ default = '[] ' ;
99
94
}
100
95
} elseif ($ node instanceof EnumNode) {
101
96
$ comments [] = 'One of ' .implode ('; ' , array_map ('json_encode ' , $ node ->getValues ()));
102
97
$ 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
98
} else {
107
99
$ default = '~ ' ;
108
100
@@ -170,7 +162,7 @@ private function writeNode(NodeInterface $node, ?NodeInterface $parentNode = nul
170
162
171
163
$ this ->writeLine ('# ' .$ message .': ' , $ depth * 4 + 4 );
172
164
173
- $ this ->writeArray (array_map ([Inline::class, 'dump ' ], $ example ), $ depth + 1 );
165
+ $ this ->writeArray (array_map ([Inline::class, 'dump ' ], $ example ), $ depth + 1 , true );
174
166
}
175
167
176
168
if ($ children ) {
@@ -191,7 +183,7 @@ private function writeLine(string $text, int $indent = 0)
191
183
$ this ->reference .= sprintf ($ format , $ text )."\n" ;
192
184
}
193
185
194
- private function writeArray (array $ array , int $ depth )
186
+ private function writeArray (array $ array , int $ depth, bool $ asComment = false )
195
187
{
196
188
$ isIndexed = array_values ($ array ) === $ array ;
197
189
@@ -202,14 +194,16 @@ private function writeArray(array $array, int $depth)
202
194
$ val = $ value ;
203
195
}
204
196
197
+ $ prefix = $ asComment ? '# ' : '' ;
198
+
205
199
if ($ isIndexed ) {
206
- $ this ->writeLine ('- ' .$ val , $ depth * 4 );
200
+ $ this ->writeLine ($ prefix . '- ' .$ val , $ depth * 4 );
207
201
} else {
208
- $ this ->writeLine (sprintf ('%-20s %s ' , $ key .': ' , $ val ), $ depth * 4 );
202
+ $ this ->writeLine (sprintf ('%s% -20s %s ' , $ prefix , $ key .': ' , $ val ), $ depth * 4 );
209
203
}
210
204
211
205
if (\is_array ($ value )) {
212
- $ this ->writeArray ($ value , $ depth + 1 );
206
+ $ this ->writeArray ($ value , $ depth + 1 , $ asComment );
213
207
}
214
208
}
215
209
}
0 commit comments