1515use Symfony \Component \Config \Definition \BooleanNode ;
1616use Symfony \Component \Config \Definition \ConfigurationInterface ;
1717use Symfony \Component \Config \Definition \EnumNode ;
18+ use Symfony \Component \Config \Definition \Exception \InvalidConfigurationException ;
1819use Symfony \Component \Config \Definition \FloatNode ;
1920use Symfony \Component \Config \Definition \IntegerNode ;
2021use Symfony \Component \Config \Definition \NodeInterface ;
2122use Symfony \Component \Config \Definition \PrototypedArrayNode ;
2223use Symfony \Component \Config \Definition \ScalarNode ;
2324use Symfony \Component \Config \Definition \VariableNode ;
25+ use Symfony \Component \Config \Loader \ParamConfigurator ;
2426
2527/**
2628 * Generate ConfigBuilders to help create valid config.
@@ -83,7 +85,7 @@ private function getFullPath(ClassBuilder $class): string
8385 return $ directory .\DIRECTORY_SEPARATOR .$ class ->getFilename ();
8486 }
8587
86- private function writeClasses ()
88+ private function writeClasses (): void
8789 {
8890 foreach ($ this ->classes as $ class ) {
8991 $ this ->buildConstructor ($ class );
@@ -95,7 +97,7 @@ private function writeClasses()
9597 $ this ->classes = [];
9698 }
9799
98- private function buildNode (NodeInterface $ node , ClassBuilder $ class , string $ namespace )
100+ private function buildNode (NodeInterface $ node , ClassBuilder $ class , string $ namespace ): void
99101 {
100102 if (!$ node instanceof ArrayNode) {
101103 throw new \LogicException ('The node was expected to be an ArrayNode. This Configuration includes an edge case not supported yet. ' );
@@ -121,7 +123,7 @@ private function buildNode(NodeInterface $node, ClassBuilder $class, string $nam
121123 }
122124 }
123125
124- private function handleArrayNode (ArrayNode $ node , ClassBuilder $ class , string $ namespace )
126+ private function handleArrayNode (ArrayNode $ node , ClassBuilder $ class , string $ namespace ): void
125127 {
126128 $ childClass = new ClassBuilder ($ namespace , $ node ->getName ());
127129 $ class ->addRequire ($ childClass );
@@ -134,20 +136,22 @@ public function NAME(array $value = []): CLASS
134136 if (null === $this->PROPERTY) {
135137 $this->PROPERTY = new CLASS($value);
136138 } elseif ([] !== $value) {
137- throw new \Symfony\Component\Config\Definition\Exception\ InvalidConfigurationException(sprintf( \'The node created by "NAME()" has already been initialized. You cannot pass values the second time you call NAME(). \'));
139+ throw new InvalidConfigurationException(sprintf( \'The node created by "NAME()" has already been initialized. You cannot pass values the second time you call NAME(). \'));
138140 }
139141
140142 return $this->PROPERTY;
141143} ' ;
144+ $ class ->addUse (InvalidConfigurationException::class);
142145 $ class ->addMethod ($ node ->getName (), $ body , ['PROPERTY ' => $ property ->getName (), 'CLASS ' => $ childClass ->getFqcn ()]);
143146
144147 $ this ->buildNode ($ node , $ childClass , $ this ->getSubNamespace ($ childClass ));
145148 }
146149
147- private function handleVariableNode (VariableNode $ node , ClassBuilder $ class )
150+ private function handleVariableNode (VariableNode $ node , ClassBuilder $ class ): void
148151 {
149152 $ comment = $ this ->getComment ($ node );
150153 $ property = $ class ->addProperty ($ node ->getName ());
154+ $ class ->addUse (ParamConfigurator::class);
151155
152156 $ body = '
153157/**
@@ -162,23 +166,24 @@ public function NAME($valueDEFAULT): self
162166 $ class ->addMethod ($ node ->getName (), $ body , ['PROPERTY ' => $ property ->getName (), 'COMMENT ' => $ comment , 'DEFAULT ' => $ node ->hasDefaultValue () ? ' = ' .var_export ($ node ->getDefaultValue (), true ) : '' ]);
163167 }
164168
165- private function handlePrototypedArrayNode (PrototypedArrayNode $ node , ClassBuilder $ class , string $ namespace )
169+ private function handlePrototypedArrayNode (PrototypedArrayNode $ node , ClassBuilder $ class , string $ namespace ): void
166170 {
167171 $ name = $ this ->getSingularName ($ node );
168172 $ prototype = $ node ->getPrototype ();
169173 $ methodName = $ name ;
170174
171175 $ parameterType = $ this ->getParameterType ($ prototype );
172176 if (null !== $ parameterType || $ prototype instanceof ScalarNode) {
177+ $ class ->addUse (ParamConfigurator::class);
173178 $ property = $ class ->addProperty ($ node ->getName ());
174179 if (null === $ key = $ node ->getKeyAttribute ()) {
175180 // This is an array of values; don't use singular name
176181 $ body = '
177182/**
178- * @param list<TYPE> $value
183+ * @param ParamConfigurator| list<TYPE|ParamConfigurator > $value
179184 * @return $this
180185 */
181- public function NAME(array $value): self
186+ public function NAME($value): self
182187{
183188 $this->PROPERTY = $value;
184189
@@ -189,16 +194,17 @@ public function NAME(array $value): self
189194 } else {
190195 $ body = '
191196/**
197+ * @param ParamConfigurator|TYPE $value
192198 * @return $this
193199 */
194- public function NAME(string $VAR, TYPE $VALUE): self
200+ public function NAME(string $VAR, $VALUE): self
195201{
196202 $this->PROPERTY[$VAR] = $VALUE;
197203
198204 return $this;
199205} ' ;
200206
201- $ class ->addMethod ($ methodName , $ body , ['PROPERTY ' => $ property ->getName (), 'TYPE ' => '' === $ parameterType ? '' : $ parameterType. ' ' , 'VAR ' => '' === $ key ? 'key ' : $ key , 'VALUE ' => 'value ' === $ key ? 'data ' : 'value ' ]);
207+ $ class ->addMethod ($ methodName , $ body , ['PROPERTY ' => $ property ->getName (), 'TYPE ' => '' === $ parameterType ? 'mixed ' : $ parameterType , 'VAR ' => '' === $ key ? 'key ' : $ key , 'VALUE ' => 'value ' === $ key ? 'data ' : 'value ' ]);
202208 }
203209
204210 return ;
@@ -227,31 +233,33 @@ public function NAME(string $VAR, array $VALUE = []): CLASS
227233 return $this->PROPERTY[$VAR];
228234 }
229235
230- throw new \Symfony\Component\Config\Definition\Exception\ InvalidConfigurationException(sprintf( \'The node created by "NAME()" has already been initialized. You cannot pass values the second time you call NAME(). \'));
236+ throw new InvalidConfigurationException(sprintf( \'The node created by "NAME()" has already been initialized. You cannot pass values the second time you call NAME(). \'));
231237} ' ;
238+ $ class ->addUse (InvalidConfigurationException::class);
232239 $ class ->addMethod ($ methodName , $ body , ['PROPERTY ' => $ property ->getName (), 'CLASS ' => $ childClass ->getFqcn (), 'VAR ' => '' === $ key ? 'key ' : $ key , 'VALUE ' => 'value ' === $ key ? 'data ' : 'value ' ]);
233240 }
234241
235242 $ this ->buildNode ($ prototype , $ childClass , $ namespace .'\\' .$ childClass ->getName ());
236243 }
237244
238- private function handleScalarNode (ScalarNode $ node , ClassBuilder $ class )
245+ private function handleScalarNode (ScalarNode $ node , ClassBuilder $ class ): void
239246 {
240247 $ comment = $ this ->getComment ($ node );
241248 $ property = $ class ->addProperty ($ node ->getName ());
249+ $ class ->addUse (ParamConfigurator::class);
242250
243251 $ body = '
244252/**
245253COMMENT * @return $this
246254 */
247- public function NAME(TYPE $value): self
255+ public function NAME($value): self
248256{
249257 $this->PROPERTY = $value;
250258
251259 return $this;
252260} ' ;
253- $ parameterType = $ this -> getParameterType ( $ node ) ?? '' ;
254- $ class ->addMethod ($ node ->getName (), $ body , ['PROPERTY ' => $ property ->getName (), 'TYPE ' => '' === $ parameterType ? '' : $ parameterType . ' ' , ' COMMENT ' => $ comment ]);
261+
262+ $ class ->addMethod ($ node ->getName (), $ body , ['PROPERTY ' => $ property ->getName (), 'COMMENT ' => $ comment ]);
255263 }
256264
257265 private function getParameterType (NodeInterface $ node ): ?string
@@ -301,9 +309,15 @@ private function getComment(VariableNode $node): string
301309 }
302310
303311 if ($ node instanceof EnumNode) {
304- $ comment .= sprintf (' * @param %s $value ' , implode ('| ' , array_map (function ($ a ) {
312+ $ comment .= sprintf (' * @param ParamConfigurator| %s $value ' , implode ('| ' , array_map (function ($ a ) {
305313 return var_export ($ a , true );
306314 }, $ node ->getValues ()))).\PHP_EOL ;
315+ } else {
316+ $ parameterType = $ this ->getParameterType ($ node );
317+ if (null === $ parameterType || '' === $ parameterType ) {
318+ $ parameterType = 'mixed ' ;
319+ }
320+ $ comment .= ' * @param ParamConfigurator| ' .$ parameterType .' $value ' .\PHP_EOL ;
307321 }
308322
309323 if ($ node ->isDeprecated ()) {
@@ -387,9 +401,10 @@ private function buildConstructor(ClassBuilder $class): void
387401
388402 $ body .= '
389403 if ($value !== []) {
390- throw new \Symfony\Component\Config\Definition\Exception\ InvalidConfigurationException(sprintf( \'The following keys are not supported by "%s": \', __CLASS__) . implode( \', \', array_keys($value)));
404+ throw new InvalidConfigurationException(sprintf( \'The following keys are not supported by "%s": \', __CLASS__) . implode( \', \', array_keys($value)));
391405 } ' ;
392406
407+ $ class ->addUse (InvalidConfigurationException::class);
393408 $ class ->addMethod ('__construct ' , '
394409public function __construct(array $value = [])
395410{
0 commit comments