88use Iterator ;
99use PHPStan \Reflection \Native \NativeParameterReflection ;
1010use PHPStan \Reflection \PassedByReference ;
11- use PHPStan \ShouldNotHappenException ;
1211use PHPStan \Testing \PHPStanTestCase ;
1312use PHPStan \TrinaryLogic ;
1413use PHPStan \Type \Accessory \AccessoryLiteralStringType ;
@@ -177,26 +176,22 @@ public function testSelfCompare(Type $type): void
177176 */
178177 public static function dataIsSuperTypeOf (): Iterator
179178 {
179+ $ int = new IntegerType ();
180+ $ string = new StringType ();
180181 $ unionTypeA = new UnionType ([
181- new IntegerType () ,
182- new StringType () ,
182+ $ int ,
183+ $ string ,
183184 ]);
184- if (
185- !isset ($ unionTypeA ->getTypes ()[0 ])
186- || !isset ($ unionTypeA ->getTypes ()[1 ])
187- ) {
188- throw new ShouldNotHappenException ();
189- }
190185
191186 yield [
192187 $ unionTypeA ,
193- $ unionTypeA -> getTypes ()[ 0 ] ,
188+ $ int ,
194189 TrinaryLogic::createYes (),
195190 ];
196191
197192 yield [
198193 $ unionTypeA ,
199- $ unionTypeA -> getTypes ()[ 1 ] ,
194+ $ string ,
200195 TrinaryLogic::createYes (),
201196 ];
202197
@@ -266,29 +261,25 @@ public static function dataIsSuperTypeOf(): Iterator
266261 TrinaryLogic::createNo (),
267262 ];
268263
264+ $ intersectionTypeB = new IntersectionType ([
265+ new ObjectType ('ArrayObject ' ),
266+ new IterableType (new MixedType (), new ObjectType ('DatePeriod ' )),
267+ ]);
268+ $ arrayTypeB = new ArrayType (new MixedType (), new ObjectType ('DatePeriod ' ));
269269 $ unionTypeB = new UnionType ([
270- new IntersectionType ([
271- new ObjectType ('ArrayObject ' ),
272- new IterableType (new MixedType (), new ObjectType ('DatePeriod ' )),
273- ]),
274- new ArrayType (new MixedType (), new ObjectType ('DatePeriod ' )),
270+ $ intersectionTypeB ,
271+ $ arrayTypeB ,
275272 ]);
276- if (
277- !isset ($ unionTypeB ->getTypes ()[0 ])
278- || !isset ($ unionTypeB ->getTypes ()[1 ])
279- ) {
280- throw new ShouldNotHappenException ();
281- }
282273
283274 yield [
284275 $ unionTypeB ,
285- $ unionTypeB -> getTypes ()[ 0 ] ,
276+ $ intersectionTypeB ,
286277 TrinaryLogic::createYes (),
287278 ];
288279
289280 yield [
290281 $ unionTypeB ,
291- $ unionTypeB -> getTypes ()[ 1 ] ,
282+ $ arrayTypeB ,
292283 TrinaryLogic::createYes (),
293284 ];
294285
@@ -486,16 +477,12 @@ public function testIsSuperTypeOf(UnionType $type, Type $otherType, TrinaryLogic
486477 */
487478 public static function dataIsSubTypeOf (): Iterator
488479 {
480+ $ int = new IntegerType ();
481+ $ string = new StringType ();
489482 $ unionTypeA = new UnionType ([
490- new IntegerType () ,
491- new StringType () ,
483+ $ int ,
484+ $ string ,
492485 ]);
493- if (
494- !isset ($ unionTypeA ->getTypes ()[0 ])
495- || !isset ($ unionTypeA ->getTypes ()[1 ])
496- ) {
497- throw new ShouldNotHappenException ();
498- }
499486
500487 yield [
501488 $ unionTypeA ,
@@ -517,13 +504,13 @@ public static function dataIsSubTypeOf(): Iterator
517504
518505 yield [
519506 $ unionTypeA ,
520- $ unionTypeA -> getTypes ()[ 0 ] ,
507+ $ int ,
521508 TrinaryLogic::createMaybe (),
522509 ];
523510
524511 yield [
525512 $ unionTypeA ,
526- $ unionTypeA -> getTypes ()[ 1 ] ,
513+ $ string ,
527514 TrinaryLogic::createMaybe (),
528515 ];
529516
@@ -581,20 +568,16 @@ public static function dataIsSubTypeOf(): Iterator
581568 TrinaryLogic::createNo (),
582569 ];
583570
571+ $ intersectionTypeB = new IntersectionType ([
572+ new ObjectType ('ArrayObject ' ),
573+ new IterableType (new MixedType (), new ObjectType ('Item ' )),
574+ new CallableType (),
575+ ]);
576+ $ arrayTypeB = new ArrayType (new MixedType (), new ObjectType ('Item ' ));
584577 $ unionTypeB = new UnionType ([
585- new IntersectionType ([
586- new ObjectType ('ArrayObject ' ),
587- new IterableType (new MixedType (), new ObjectType ('Item ' )),
588- new CallableType (),
589- ]),
590- new ArrayType (new MixedType (), new ObjectType ('Item ' )),
578+ $ intersectionTypeB ,
579+ $ arrayTypeB ,
591580 ]);
592- if (
593- !isset ($ unionTypeB ->getTypes ()[0 ])
594- || !isset ($ unionTypeB ->getTypes ()[1 ])
595- ) {
596- throw new ShouldNotHappenException ();
597- }
598581
599582 yield [
600583 $ unionTypeB ,
@@ -616,13 +599,13 @@ public static function dataIsSubTypeOf(): Iterator
616599
617600 yield [
618601 $ unionTypeB ,
619- $ unionTypeB -> getTypes ()[ 0 ] ,
602+ $ intersectionTypeB ,
620603 TrinaryLogic::createMaybe (),
621604 ];
622605
623606 yield [
624607 $ unionTypeB ,
625- $ unionTypeB -> getTypes ()[ 1 ] ,
608+ $ arrayTypeB ,
626609 TrinaryLogic::createMaybe (),
627610 ];
628611
0 commit comments