@@ -126,10 +126,13 @@ private function handleArrayNode(ArrayNode $node, ClassBuilder $class, string $n
126126 $ class ->addRequire ($ childClass );
127127 $ this ->classes [] = $ childClass ;
128128
129+ $ nodeTypes = $ this ->getParameterTypes ($ node );
130+ $ paramType = $ this ->getParamType ($ nodeTypes );
131+
129132 $ hasNormalizationClosures = $ this ->hasNormalizationClosures ($ node );
130133 $ comment = $ this ->getComment ($ node );
131- if ($ hasNormalizationClosures ) {
132- $ comment = \sprintf (" * @template TValue \n * @param TValue \$value \n%s " , $ comment );
134+ if ($ hasNormalizationClosures && ' array ' !== $ paramType ) {
135+ $ comment = \sprintf (" * @template TValue of %s \n * @param TValue \$value \n%s " , $ paramType , $ comment );
133136 $ comment .= \sprintf (' * @return %s|$this ' ."\n" , $ childClass ->getFqcn ());
134137 $ comment .= \sprintf (' * @psalm-return (TValue is array ? %s : static) ' ."\n " , $ childClass ->getFqcn ());
135138 }
@@ -141,8 +144,7 @@ private function handleArrayNode(ArrayNode $node, ClassBuilder $class, string $n
141144 $ node ->getName (),
142145 $ this ->getType ($ childClass ->getFqcn (), $ hasNormalizationClosures )
143146 );
144- $ nodeTypes = $ this ->getParameterTypes ($ node );
145- $ body = $ hasNormalizationClosures ? '
147+ $ body = $ hasNormalizationClosures && 'array ' !== $ paramType ? '
146148COMMENTpublic function NAME(PARAM_TYPE $value = []): CLASS|static
147149{
148150 if (!\is_array($value)) {
@@ -177,7 +179,7 @@ private function handleArrayNode(ArrayNode $node, ClassBuilder $class, string $n
177179 'COMMENT ' => $ comment ,
178180 'PROPERTY ' => $ property ->getName (),
179181 'CLASS ' => $ childClass ->getFqcn (),
180- 'PARAM_TYPE ' => \in_array ( ' mixed ' , $ nodeTypes , true ) ? ' mixed ' : implode ( ' | ' , $ nodeTypes ) ,
182+ 'PARAM_TYPE ' => $ paramType ,
181183 ]);
182184
183185 $ this ->buildNode ($ node , $ childClass , $ this ->getSubNamespace ($ childClass ));
@@ -217,10 +219,11 @@ private function handlePrototypedArrayNode(PrototypedArrayNode $node, ClassBuild
217219
218220 $ nodeParameterTypes = $ this ->getParameterTypes ($ node );
219221 $ prototypeParameterTypes = $ this ->getParameterTypes ($ prototype );
222+ $ noKey = null === $ key = $ node ->getKeyAttribute ();
220223 if (!$ prototype instanceof ArrayNode || ($ prototype instanceof PrototypedArrayNode && $ prototype ->getPrototype () instanceof ScalarNode)) {
221224 $ class ->addUse (ParamConfigurator::class);
222225 $ property = $ class ->addProperty ($ node ->getName ());
223- if (null === $ key = $ node -> getKeyAttribute () ) {
226+ if ($ noKey ) {
224227 // This is an array of values; don't use singular name
225228 $ nodeTypesWithoutArray = array_filter ($ nodeParameterTypes , static fn ($ type ) => 'array ' !== $ type );
226229 $ body = '
@@ -241,7 +244,7 @@ public function NAME(PARAM_TYPE $value): static
241244 'PROPERTY ' => $ property ->getName (),
242245 'PROTOTYPE_TYPE ' => implode ('| ' , $ prototypeParameterTypes ),
243246 'EXTRA_TYPE ' => $ nodeTypesWithoutArray ? '| ' .implode ('| ' , $ nodeTypesWithoutArray ) : '' ,
244- 'PARAM_TYPE ' => \in_array ( ' mixed ' , $ nodeParameterTypes , true ) ? ' mixed ' : ' ParamConfigurator| ' . implode ( ' | ' , $ nodeParameterTypes ),
247+ 'PARAM_TYPE ' => $ this -> getParamType ( $ nodeParameterTypes , true ),
245248 ]);
246249 } else {
247250 $ body = '
@@ -258,7 +261,7 @@ public function NAME(string $VAR, TYPE $VALUE): static
258261
259262 $ class ->addMethod ($ methodName , $ body , [
260263 'PROPERTY ' => $ property ->getName (),
261- 'TYPE ' => \in_array ( ' mixed ' , $ prototypeParameterTypes , true ) ? ' mixed ' : ' ParamConfigurator| ' . implode ( ' | ' , $ prototypeParameterTypes ),
264+ 'TYPE ' => $ this -> getParamType ( $ prototypeParameterTypes , true ),
262265 'VAR ' => '' === $ key ? 'key ' : $ key ,
263266 'VALUE ' => 'value ' === $ key ? 'data ' : 'value ' ,
264267 ]);
@@ -279,18 +282,27 @@ public function NAME(string $VAR, TYPE $VALUE): static
279282 $ this ->getType ($ childClass ->getFqcn ().'[] ' , $ hasNormalizationClosures )
280283 );
281284
285+ $ paramType = $ this ->getParamType ($ noKey ? $ nodeParameterTypes : $ prototypeParameterTypes );
286+
282287 $ comment = $ this ->getComment ($ node );
288+ <<<<<<< HEAD
283289 if ($ hasNormalizationClosures ) {
284290 $ comment = \sprintf (" * @template TValue \n * @param TValue \$value \n%s " , $ comment );
285291 $ comment .= \sprintf (' * @return %s|$this ' ."\n" , $ childClass ->getFqcn ());
286292 $ comment .= \sprintf (' * @psalm-return (TValue is array ? %s : static) ' ."\n " , $ childClass ->getFqcn ());
293+ =======
294+ if ($ hasNormalizationClosures && 'array ' !== $ paramType ) {
295+ $ comment = sprintf (" * @template TValue of %s \n * @param TValue \$value \n%s " , $ paramType , $ comment );
296+ $ comment .= sprintf (' * @return %s|$this ' ."\n" , $ childClass ->getFqcn ());
297+ $ comment .= sprintf (' * @psalm-return (TValue is array ? %s : static) ' ."\n " , $ childClass ->getFqcn ());
298+ >>>>>>> 100 c683018d ([Config] Do not generate unreachable configuration paths)
287299 }
288300 if ('' !== $ comment ) {
289301 $ comment = "/** \n$ comment*/ \n" ;
290302 }
291303
292- if (null === $ key = $ node -> getKeyAttribute () ) {
293- $ body = $ hasNormalizationClosures ? '
304+ if ($ noKey ) {
305+ $ body = $ hasNormalizationClosures && ' array ' !== $ paramType ? '
294306COMMENTpublic function NAME(PARAM_TYPE $value = []): CLASS|static
295307{
296308 $this->_usedProperties[ \'PROPERTY \'] = true;
@@ -312,10 +324,10 @@ public function NAME(string $VAR, TYPE $VALUE): static
312324 'COMMENT ' => $ comment ,
313325 'PROPERTY ' => $ property ->getName (),
314326 'CLASS ' => $ childClass ->getFqcn (),
315- 'PARAM_TYPE ' => \in_array ( ' mixed ' , $ nodeParameterTypes , true ) ? ' mixed ' : implode ( ' | ' , $ nodeParameterTypes ) ,
327+ 'PARAM_TYPE ' => $ paramType ,
316328 ]);
317329 } else {
318- $ body = $ hasNormalizationClosures ? '
330+ $ body = $ hasNormalizationClosures && ' array ' !== $ paramType ? '
319331COMMENTpublic function NAME(string $VAR, PARAM_TYPE $VALUE = []): CLASS|static
320332{
321333 if (!\is_array($VALUE)) {
@@ -351,7 +363,7 @@ public function NAME(string $VAR, TYPE $VALUE): static
351363 'CLASS ' => $ childClass ->getFqcn (),
352364 'VAR ' => '' === $ key ? 'key ' : $ key ,
353365 'VALUE ' => 'value ' === $ key ? 'data ' : 'value ' ,
354- 'PARAM_TYPE ' => \in_array ( ' mixed ' , $ prototypeParameterTypes , true ) ? ' mixed ' : implode ( ' | ' , $ prototypeParameterTypes ) ,
366+ 'PARAM_TYPE ' => $ paramType ,
355367 ]);
356368 }
357369
@@ -596,4 +608,9 @@ private function getType(string $classType, bool $hasNormalizationClosures): str
596608 {
597609 return $ classType .($ hasNormalizationClosures ? '|scalar ' : '' );
598610 }
611+
612+ private function getParamType (array $ types , bool $ withParamConfigurator = false ): string
613+ {
614+ return \in_array ('mixed ' , $ types , true ) ? 'mixed ' : ($ withParamConfigurator ? 'ParamConfigurator| ' : '' ).implode ('| ' , $ types );
615+ }
599616}
0 commit comments