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