File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 37
37
use function md5 ;
38
38
use function sprintf ;
39
39
use function usort ;
40
+ use const PHP_INT_MAX ;
41
+ use const PHP_INT_MIN ;
40
42
41
43
/**
42
44
* @api
@@ -185,6 +187,7 @@ public static function union(Type ...$types): Type
185
187
$ scalarTypes = [];
186
188
$ hasGenericScalarTypes = [];
187
189
$ enumCaseTypes = [];
190
+ $ integerRangeTypes = [];
188
191
for ($ i = 0 ; $ i < $ typesCount ; $ i ++) {
189
192
if ($ types [$ i ] instanceof ConstantScalarType) {
190
193
$ type = $ types [$ i ];
@@ -212,6 +215,13 @@ public static function union(Type ...$types): Type
212
215
continue ;
213
216
}
214
217
218
+ if ($ types [$ i ] instanceof IntegerRangeType) {
219
+ $ integerRangeTypes [] = $ types [$ i ];
220
+ unset($ types [$ i ]);
221
+
222
+ continue ;
223
+ }
224
+
215
225
if (!$ types [$ i ]->isArray ()->yes ()) {
216
226
continue ;
217
227
}
@@ -225,6 +235,12 @@ public static function union(Type ...$types): Type
225
235
}
226
236
227
237
$ enumCaseTypes = array_values ($ enumCaseTypes );
238
+ usort (
239
+ $ integerRangeTypes ,
240
+ static fn (IntegerRangeType $ a , IntegerRangeType $ b ): int => ($ a ->getMin () ?? PHP_INT_MIN ) <=> ($ b ->getMin () ?? PHP_INT_MIN )
241
+ ?: ($ a ->getMax () ?? PHP_INT_MAX ) <=> ($ b ->getMax () ?? PHP_INT_MAX )
242
+ );
243
+ $ types = array_merge ($ types , $ integerRangeTypes );
228
244
$ types = array_values ($ types );
229
245
$ typesCount = count ($ types );
230
246
Original file line number Diff line number Diff line change @@ -1558,6 +1558,25 @@ public function dataUnion(): iterable
1558
1558
UnionType::class,
1559
1559
'int<1, 3>|int<7, 9> ' ,
1560
1560
],
1561
+ [
1562
+ [
1563
+ IntegerRangeType::fromInterval (4 , 9 ),
1564
+ IntegerRangeType::fromInterval (16 , 81 ),
1565
+ IntegerRangeType::fromInterval (8 , 27 ),
1566
+ ],
1567
+ IntegerRangeType::class,
1568
+ 'int<4, 81> ' ,
1569
+ ],
1570
+ [
1571
+ [
1572
+ IntegerRangeType::fromInterval (8 , 27 ),
1573
+ IntegerRangeType::fromInterval (4 , 6 ),
1574
+ new ConstantIntegerType (7 ),
1575
+ IntegerRangeType::fromInterval (16 , 81 ),
1576
+ ],
1577
+ IntegerRangeType::class,
1578
+ 'int<4, 81> ' ,
1579
+ ],
1561
1580
[
1562
1581
[
1563
1582
IntegerRangeType::fromInterval (1 , 3 ),
You can’t perform that action at this time.
0 commit comments