File tree 2 files changed +50
-2
lines changed
2 files changed +50
-2
lines changed Original file line number Diff line number Diff line change @@ -1559,7 +1559,12 @@ public function makeOffsetRequired(Type $offsetType): self
1559
1559
public function toPhpDocNode (): TypeNode
1560
1560
{
1561
1561
$ items = [];
1562
+ $ values = [];
1563
+ $ exportValuesOnly = true ;
1562
1564
foreach ($ this ->keyTypes as $ i => $ keyType ) {
1565
+ if ($ keyType ->getValue () !== $ i ) {
1566
+ $ exportValuesOnly = false ;
1567
+ }
1563
1568
$ keyPhpDocNode = $ keyType ->toPhpDocNode ();
1564
1569
if (!$ keyPhpDocNode instanceof ConstTypeNode) {
1565
1570
continue ;
@@ -1574,14 +1579,24 @@ public function toPhpDocNode(): TypeNode
1574
1579
$ keyNode = new IdentifierTypeNode ($ value );
1575
1580
}
1576
1581
}
1582
+
1583
+ $ isOptional = $ this ->isOptionalKey ($ i );
1584
+ if ($ isOptional ) {
1585
+ $ exportValuesOnly = false ;
1586
+ }
1577
1587
$ items [] = new ArrayShapeItemNode (
1578
1588
$ keyNode ,
1579
- $ this ->isOptionalKey ($ i ),
1589
+ $ isOptional ,
1590
+ $ valueType ->toPhpDocNode (),
1591
+ );
1592
+ $ values [] = new ArrayShapeItemNode (
1593
+ null ,
1594
+ $ isOptional ,
1580
1595
$ valueType ->toPhpDocNode (),
1581
1596
);
1582
1597
}
1583
1598
1584
- return new ArrayShapeNode ($ items );
1599
+ return new ArrayShapeNode ($ exportValuesOnly ? $ values : $ items );
1585
1600
}
1586
1601
1587
1602
public static function isValidIdentifier (string $ value ): bool
Original file line number Diff line number Diff line change @@ -254,6 +254,39 @@ public function dataToPhpDocNode(): iterable
254
254
]),
255
255
'non-empty-list<mixed> ' ,
256
256
];
257
+
258
+ yield [
259
+ new ConstantArrayType ([
260
+ new ConstantIntegerType (0 ),
261
+ new ConstantIntegerType (1 ),
262
+ ], [
263
+ new ConstantStringType ('foo ' ),
264
+ new ConstantStringType ('bar ' ),
265
+ ]),
266
+ "array{'foo', 'bar'} " ,
267
+ ];
268
+
269
+ yield [
270
+ new ConstantArrayType ([
271
+ new ConstantIntegerType (0 ),
272
+ new ConstantIntegerType (2 ),
273
+ ], [
274
+ new ConstantStringType ('foo ' ),
275
+ new ConstantStringType ('bar ' ),
276
+ ]),
277
+ "array{0: 'foo', 2: 'bar'} " ,
278
+ ];
279
+
280
+ yield [
281
+ new ConstantArrayType ([
282
+ new ConstantIntegerType (0 ),
283
+ new ConstantIntegerType (1 ),
284
+ ], [
285
+ new ConstantStringType ('foo ' ),
286
+ new ConstantStringType ('bar ' ),
287
+ ], [2 ], [1 ]),
288
+ "array{0: 'foo', 1?: 'bar'} " ,
289
+ ];
257
290
}
258
291
259
292
/**
You can’t perform that action at this time.
0 commit comments