@@ -203,7 +203,7 @@ public function unionWith(Type $otherType) {
203
203
$ thisSubtypes = $ this ->type === self ::TYPE_UNION ? $ this ->subTypes : [$ this ];
204
204
$ otherSubtypes = $ otherType ->type === self ::TYPE_UNION ? $ otherType ->subTypes : [$ otherType ];
205
205
$ subtypes = self ::unique (array_merge ($ thisSubtypes , $ otherSubtypes ));
206
- return new self (self ::TYPE_UNION , $ subtypes );
206
+ return count ( $ subtypes ) === 1 ? $ subtypes [ 0 ] : new self (self ::TYPE_UNION , $ subtypes );
207
207
}
208
208
209
209
/**
@@ -217,7 +217,7 @@ public function intersectionWith(Type $otherType) {
217
217
$ thisSubtypes = $ this ->type === self ::TYPE_INTERSECTION ? $ this ->subTypes : [$ this ];
218
218
$ otherSubtypes = $ otherType ->type === self ::TYPE_INTERSECTION ? $ otherType ->subTypes : [$ otherType ];
219
219
$ subtypes = self ::unique (array_merge ($ thisSubtypes , $ otherSubtypes ));
220
- return new self (self ::TYPE_INTERSECTION , $ subtypes );
220
+ return count ( $ subtypes ) === 1 ? $ subtypes [ 0 ] : new self (self ::TYPE_INTERSECTION , $ subtypes );
221
221
}
222
222
223
223
/**
@@ -355,9 +355,10 @@ public static function getPrimitives() {
355
355
* @return Type|null
356
356
*/
357
357
public static function union ($ types ) {
358
+ /** @var Type|null $result */
358
359
$ result = null ;
359
360
foreach ($ types as $ type ) {
360
- $ result = $ result === null ? $ type : $ type ->unionWith ($ result );
361
+ $ result = $ result === null ? $ type : $ result ->unionWith ($ type );
361
362
}
362
363
return $ result ;
363
364
}
@@ -367,9 +368,10 @@ public static function union($types) {
367
368
* @return Type|null
368
369
*/
369
370
public static function intersection ($ types ) {
371
+ /** @var Type|null $result */
370
372
$ result = null ;
371
373
foreach ($ types as $ type ) {
372
- $ result = $ result === null ? $ type : $ type ->intersectionWith ($ result );
374
+ $ result = $ result === null ? $ type : $ result ->intersectionWith ($ type );
373
375
}
374
376
return $ result ;
375
377
}
0 commit comments