@@ -127,10 +127,13 @@ private function handleArrayNode(ArrayNode $node, ClassBuilder $class, string $n
127127 $ class ->addRequire ($ childClass );
128128 $ this ->classes [] = $ childClass ;
129129
130+ $ nodeTypes = $ this ->getParameterTypes ($ node );
131+ $ paramType = $ this ->getParamType ($ nodeTypes );
132+
130133 $ hasNormalizationClosures = $ this ->hasNormalizationClosures ($ node );
131134 $ comment = $ this ->getComment ($ node );
132- if ($ hasNormalizationClosures ) {
133- $ comment = \sprintf (" * @template TValue \n * @param TValue \$value \n%s " , $ comment );
135+ if ($ hasNormalizationClosures && ' array ' !== $ paramType ) {
136+ $ comment = \sprintf (" * @template TValue of %s \n * @param TValue \$value \n%s " , $ paramType , $ comment );
134137 $ comment .= \sprintf (' * @return %s|$this ' ."\n" , $ childClass ->getFqcn ());
135138 $ comment .= \sprintf (' * @psalm-return (TValue is array ? %s : static) ' ."\n " , $ childClass ->getFqcn ());
136139 }
@@ -142,8 +145,7 @@ private function handleArrayNode(ArrayNode $node, ClassBuilder $class, string $n
142145 $ node ->getName (),
143146 $ this ->getType ($ childClass ->getFqcn (), $ hasNormalizationClosures )
144147 );
145- $ nodeTypes = $ this ->getParameterTypes ($ node );
146- $ body = $ hasNormalizationClosures ? '
148+ $ body = $ hasNormalizationClosures && 'array ' !== $ paramType ? '
147149COMMENTpublic function NAME(PARAM_TYPE $value = []): CLASS|static
148150{
149151 if (!\is_array($value)) {
@@ -178,7 +180,7 @@ private function handleArrayNode(ArrayNode $node, ClassBuilder $class, string $n
178180 'COMMENT ' => $ comment ,
179181 'PROPERTY ' => $ property ->getName (),
180182 'CLASS ' => $ childClass ->getFqcn (),
181- 'PARAM_TYPE ' => \in_array ( ' mixed ' , $ nodeTypes , true ) ? ' mixed ' : implode ( ' | ' , $ nodeTypes ) ,
183+ 'PARAM_TYPE ' => $ paramType ,
182184 ]);
183185
184186 $ this ->buildNode ($ node , $ childClass , $ this ->getSubNamespace ($ childClass ));
@@ -218,10 +220,11 @@ private function handlePrototypedArrayNode(PrototypedArrayNode $node, ClassBuild
218220
219221 $ nodeParameterTypes = $ this ->getParameterTypes ($ node );
220222 $ prototypeParameterTypes = $ this ->getParameterTypes ($ prototype );
223+ $ noKey = null === $ key = $ node ->getKeyAttribute ();
221224 if (!$ prototype instanceof ArrayNode || ($ prototype instanceof PrototypedArrayNode && $ prototype ->getPrototype () instanceof ScalarNode)) {
222225 $ class ->addUse (ParamConfigurator::class);
223226 $ property = $ class ->addProperty ($ node ->getName ());
224- if (null === $ key = $ node -> getKeyAttribute () ) {
227+ if ($ noKey ) {
225228 // This is an array of values; don't use singular name
226229 $ nodeTypesWithoutArray = array_filter ($ nodeParameterTypes , static fn ($ type ) => 'array ' !== $ type );
227230 $ body = '
@@ -242,7 +245,7 @@ public function NAME(PARAM_TYPE $value): static
242245 'PROPERTY ' => $ property ->getName (),
243246 'PROTOTYPE_TYPE ' => implode ('| ' , $ prototypeParameterTypes ),
244247 'EXTRA_TYPE ' => $ nodeTypesWithoutArray ? '| ' .implode ('| ' , $ nodeTypesWithoutArray ) : '' ,
245- 'PARAM_TYPE ' => \in_array ( ' mixed ' , $ nodeParameterTypes , true ) ? ' mixed ' : ' ParamConfigurator| ' . implode ( ' | ' , $ nodeParameterTypes ),
248+ 'PARAM_TYPE ' => $ this -> getParamType ( $ nodeParameterTypes , true ),
246249 ]);
247250 } else {
248251 $ body = '
@@ -259,7 +262,7 @@ public function NAME(string $VAR, TYPE $VALUE): static
259262
260263 $ class ->addMethod ($ methodName , $ body , [
261264 'PROPERTY ' => $ property ->getName (),
262- 'TYPE ' => \in_array ( ' mixed ' , $ prototypeParameterTypes , true ) ? ' mixed ' : ' ParamConfigurator| ' . implode ( ' | ' , $ prototypeParameterTypes ),
265+ 'TYPE ' => $ this -> getParamType ( $ prototypeParameterTypes , true ),
263266 'VAR ' => '' === $ key ? 'key ' : $ key ,
264267 'VALUE ' => 'value ' === $ key ? 'data ' : 'value ' ,
265268 ]);
@@ -280,18 +283,27 @@ public function NAME(string $VAR, TYPE $VALUE): static
280283 $ this ->getType ($ childClass ->getFqcn ().'[] ' , $ hasNormalizationClosures )
281284 );
282285
286+ $ paramType = $ this ->getParamType ($ noKey ? $ nodeParameterTypes : $ prototypeParameterTypes );
287+
283288 $ comment = $ this ->getComment ($ node );
289+ <<<<<<< HEAD
284290 if ($ hasNormalizationClosures ) {
285291 $ comment = \sprintf (" * @template TValue \n * @param TValue \$value \n%s " , $ comment );
286292 $ comment .= \sprintf (' * @return %s|$this ' ."\n" , $ childClass ->getFqcn ());
287293 $ comment .= \sprintf (' * @psalm-return (TValue is array ? %s : static) ' ."\n " , $ childClass ->getFqcn ());
294+ =======
295+ if ($ hasNormalizationClosures && 'array ' !== $ paramType ) {
296+ $ comment = sprintf (" * @template TValue of %s \n * @param TValue \$value \n%s " , $ paramType , $ comment );
297+ $ comment .= sprintf (' * @return %s|$this ' ."\n" , $ childClass ->getFqcn ());
298+ $ comment .= sprintf (' * @psalm-return (TValue is array ? %s : static) ' ."\n " , $ childClass ->getFqcn ());
299+ >>>>>>> 100 c683018d ([Config] Do not generate unreachable configuration paths)
288300 }
289301 if ('' !== $ comment ) {
290302 $ comment = "/** \n$ comment*/ \n" ;
291303 }
292304
293- if (null === $ key = $ node -> getKeyAttribute () ) {
294- $ body = $ hasNormalizationClosures ? '
305+ if ($ noKey ) {
306+ $ body = $ hasNormalizationClosures && ' array ' !== $ paramType ? '
295307COMMENTpublic function NAME(PARAM_TYPE $value = []): CLASS|static
296308{
297309 $this->_usedProperties[ \'PROPERTY \'] = true;
@@ -313,10 +325,10 @@ public function NAME(string $VAR, TYPE $VALUE): static
313325 'COMMENT ' => $ comment ,
314326 'PROPERTY ' => $ property ->getName (),
315327 'CLASS ' => $ childClass ->getFqcn (),
316- 'PARAM_TYPE ' => \in_array ( ' mixed ' , $ nodeParameterTypes , true ) ? ' mixed ' : implode ( ' | ' , $ nodeParameterTypes ) ,
328+ 'PARAM_TYPE ' => $ paramType ,
317329 ]);
318330 } else {
319- $ body = $ hasNormalizationClosures ? '
331+ $ body = $ hasNormalizationClosures && ' array ' !== $ paramType ? '
320332COMMENTpublic function NAME(string $VAR, PARAM_TYPE $VALUE = []): CLASS|static
321333{
322334 if (!\is_array($VALUE)) {
@@ -352,7 +364,7 @@ public function NAME(string $VAR, TYPE $VALUE): static
352364 'CLASS ' => $ childClass ->getFqcn (),
353365 'VAR ' => '' === $ key ? 'key ' : $ key ,
354366 'VALUE ' => 'value ' === $ key ? 'data ' : 'value ' ,
355- 'PARAM_TYPE ' => \in_array ( ' mixed ' , $ prototypeParameterTypes , true ) ? ' mixed ' : implode ( ' | ' , $ prototypeParameterTypes ) ,
367+ 'PARAM_TYPE ' => $ paramType ,
356368 ]);
357369 }
358370
@@ -597,4 +609,9 @@ private function getType(string $classType, bool $hasNormalizationClosures): str
597609 {
598610 return $ classType .($ hasNormalizationClosures ? '|scalar ' : '' );
599611 }
612+
613+ private function getParamType (array $ types , bool $ withParamConfigurator = false ): string
614+ {
615+ return \in_array ('mixed ' , $ types , true ) ? 'mixed ' : ($ withParamConfigurator ? 'ParamConfigurator| ' : '' ).implode ('| ' , $ types );
616+ }
600617}
0 commit comments