@@ -127,10 +127,13 @@ private function handleArrayNode(ArrayNode $node, ClassBuilder $class, string $n
127
127
$ class ->addRequire ($ childClass );
128
128
$ this ->classes [] = $ childClass ;
129
129
130
+ $ nodeTypes = $ this ->getParameterTypes ($ node );
131
+ $ paramType = $ this ->getParamType ($ nodeTypes );
132
+
130
133
$ hasNormalizationClosures = $ this ->hasNormalizationClosures ($ node );
131
134
$ 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 );
134
137
$ comment .= \sprintf (' * @return %s|$this ' ."\n" , $ childClass ->getFqcn ());
135
138
$ comment .= \sprintf (' * @psalm-return (TValue is array ? %s : static) ' ."\n " , $ childClass ->getFqcn ());
136
139
}
@@ -142,8 +145,7 @@ private function handleArrayNode(ArrayNode $node, ClassBuilder $class, string $n
142
145
$ node ->getName (),
143
146
$ this ->getType ($ childClass ->getFqcn (), $ hasNormalizationClosures )
144
147
);
145
- $ nodeTypes = $ this ->getParameterTypes ($ node );
146
- $ body = $ hasNormalizationClosures ? '
148
+ $ body = $ hasNormalizationClosures && 'array ' !== $ paramType ? '
147
149
COMMENTpublic function NAME(PARAM_TYPE $value = []): CLASS|static
148
150
{
149
151
if (!\is_array($value)) {
@@ -178,7 +180,7 @@ private function handleArrayNode(ArrayNode $node, ClassBuilder $class, string $n
178
180
'COMMENT ' => $ comment ,
179
181
'PROPERTY ' => $ property ->getName (),
180
182
'CLASS ' => $ childClass ->getFqcn (),
181
- 'PARAM_TYPE ' => \in_array ( ' mixed ' , $ nodeTypes , true ) ? ' mixed ' : implode ( ' | ' , $ nodeTypes ) ,
183
+ 'PARAM_TYPE ' => $ paramType ,
182
184
]);
183
185
184
186
$ this ->buildNode ($ node , $ childClass , $ this ->getSubNamespace ($ childClass ));
@@ -218,10 +220,11 @@ private function handlePrototypedArrayNode(PrototypedArrayNode $node, ClassBuild
218
220
219
221
$ nodeParameterTypes = $ this ->getParameterTypes ($ node );
220
222
$ prototypeParameterTypes = $ this ->getParameterTypes ($ prototype );
223
+ $ noKey = null === $ key = $ node ->getKeyAttribute ();
221
224
if (!$ prototype instanceof ArrayNode || ($ prototype instanceof PrototypedArrayNode && $ prototype ->getPrototype () instanceof ScalarNode)) {
222
225
$ class ->addUse (ParamConfigurator::class);
223
226
$ property = $ class ->addProperty ($ node ->getName ());
224
- if (null === $ key = $ node -> getKeyAttribute () ) {
227
+ if ($ noKey ) {
225
228
// This is an array of values; don't use singular name
226
229
$ nodeTypesWithoutArray = array_filter ($ nodeParameterTypes , static fn ($ type ) => 'array ' !== $ type );
227
230
$ body = '
@@ -242,7 +245,7 @@ public function NAME(PARAM_TYPE $value): static
242
245
'PROPERTY ' => $ property ->getName (),
243
246
'PROTOTYPE_TYPE ' => implode ('| ' , $ prototypeParameterTypes ),
244
247
'EXTRA_TYPE ' => $ nodeTypesWithoutArray ? '| ' .implode ('| ' , $ nodeTypesWithoutArray ) : '' ,
245
- 'PARAM_TYPE ' => \in_array ( ' mixed ' , $ nodeParameterTypes , true ) ? ' mixed ' : ' ParamConfigurator| ' . implode ( ' | ' , $ nodeParameterTypes ),
248
+ 'PARAM_TYPE ' => $ this -> getParamType ( $ nodeParameterTypes , true ),
246
249
]);
247
250
} else {
248
251
$ body = '
@@ -259,7 +262,7 @@ public function NAME(string $VAR, TYPE $VALUE): static
259
262
260
263
$ class ->addMethod ($ methodName , $ body , [
261
264
'PROPERTY ' => $ property ->getName (),
262
- 'TYPE ' => \in_array ( ' mixed ' , $ prototypeParameterTypes , true ) ? ' mixed ' : ' ParamConfigurator| ' . implode ( ' | ' , $ prototypeParameterTypes ),
265
+ 'TYPE ' => $ this -> getParamType ( $ prototypeParameterTypes , true ),
263
266
'VAR ' => '' === $ key ? 'key ' : $ key ,
264
267
'VALUE ' => 'value ' === $ key ? 'data ' : 'value ' ,
265
268
]);
@@ -280,18 +283,27 @@ public function NAME(string $VAR, TYPE $VALUE): static
280
283
$ this ->getType ($ childClass ->getFqcn ().'[] ' , $ hasNormalizationClosures )
281
284
);
282
285
286
+ $ paramType = $ this ->getParamType ($ noKey ? $ nodeParameterTypes : $ prototypeParameterTypes );
287
+
283
288
$ comment = $ this ->getComment ($ node );
289
+ <<<<<<< HEAD
284
290
if ($ hasNormalizationClosures ) {
285
291
$ comment = \sprintf (" * @template TValue \n * @param TValue \$value \n%s " , $ comment );
286
292
$ comment .= \sprintf (' * @return %s|$this ' ."\n" , $ childClass ->getFqcn ());
287
293
$ 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)
288
300
}
289
301
if ('' !== $ comment ) {
290
302
$ comment = "/** \n$ comment*/ \n" ;
291
303
}
292
304
293
- if (null === $ key = $ node -> getKeyAttribute () ) {
294
- $ body = $ hasNormalizationClosures ? '
305
+ if ($ noKey ) {
306
+ $ body = $ hasNormalizationClosures && ' array ' !== $ paramType ? '
295
307
COMMENTpublic function NAME(PARAM_TYPE $value = []): CLASS|static
296
308
{
297
309
$this->_usedProperties[ \'PROPERTY \'] = true;
@@ -313,10 +325,10 @@ public function NAME(string $VAR, TYPE $VALUE): static
313
325
'COMMENT ' => $ comment ,
314
326
'PROPERTY ' => $ property ->getName (),
315
327
'CLASS ' => $ childClass ->getFqcn (),
316
- 'PARAM_TYPE ' => \in_array ( ' mixed ' , $ nodeParameterTypes , true ) ? ' mixed ' : implode ( ' | ' , $ nodeParameterTypes ) ,
328
+ 'PARAM_TYPE ' => $ paramType ,
317
329
]);
318
330
} else {
319
- $ body = $ hasNormalizationClosures ? '
331
+ $ body = $ hasNormalizationClosures && ' array ' !== $ paramType ? '
320
332
COMMENTpublic function NAME(string $VAR, PARAM_TYPE $VALUE = []): CLASS|static
321
333
{
322
334
if (!\is_array($VALUE)) {
@@ -352,7 +364,7 @@ public function NAME(string $VAR, TYPE $VALUE): static
352
364
'CLASS ' => $ childClass ->getFqcn (),
353
365
'VAR ' => '' === $ key ? 'key ' : $ key ,
354
366
'VALUE ' => 'value ' === $ key ? 'data ' : 'value ' ,
355
- 'PARAM_TYPE ' => \in_array ( ' mixed ' , $ prototypeParameterTypes , true ) ? ' mixed ' : implode ( ' | ' , $ prototypeParameterTypes ) ,
367
+ 'PARAM_TYPE ' => $ paramType ,
356
368
]);
357
369
}
358
370
@@ -597,4 +609,9 @@ private function getType(string $classType, bool $hasNormalizationClosures): str
597
609
{
598
610
return $ classType .($ hasNormalizationClosures ? '|scalar ' : '' );
599
611
}
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
+ }
600
617
}
0 commit comments