File tree Expand file tree Collapse file tree 4 files changed +15
-29
lines changed Expand file tree Collapse file tree 4 files changed +15
-29
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,16 @@ class IntersectionType implements CompoundType
3333 */
3434 public function __construct (array $ types )
3535 {
36+ if (count ($ types ) < 2 ) {
37+ throw new \PHPStan \ShouldNotHappenException (sprintf (
38+ 'Cannot create %s with: %s ' ,
39+ self ::class,
40+ implode (', ' , array_map (static function (Type $ type ): string {
41+ return $ type ->describe (VerbosityLevel::value ());
42+ }, $ types ))
43+ ));
44+ }
45+
3646 $ this ->types = UnionTypeHelper::sortTypes ($ types );
3747 }
3848
Original file line number Diff line number Diff line change 55use PHPStan \Reflection \Native \NativeParameterReflection ;
66use PHPStan \Reflection \PassedByReference ;
77use PHPStan \TrinaryLogic ;
8+ use PHPStan \Type \Accessory \AccessoryNonEmptyStringType ;
89use PHPStan \Type \Accessory \HasMethodType ;
910use PHPStan \Type \Constant \ConstantArrayType ;
1011use PHPStan \Type \Constant \ConstantIntegerType ;
@@ -99,17 +100,12 @@ public function dataIsSubTypeOf(): array
99100 ],
100101 [
101102 new CallableType (),
102- new IntersectionType ([new CallableType ()]),
103- TrinaryLogic::createYes (),
104- ],
105- [
106- new CallableType (),
107- new IntersectionType ([new StringType ()]),
103+ new IntersectionType ([new StringType (), new AccessoryNonEmptyStringType ()]),
108104 TrinaryLogic::createMaybe (),
109105 ],
110106 [
111107 new CallableType (),
112- new IntersectionType ([ new IntegerType ()] ),
108+ new IntegerType (),
113109 TrinaryLogic::createNo (),
114110 ],
115111 [
Original file line number Diff line number Diff line change @@ -147,16 +147,6 @@ public function dataIsSuperTypeOf(): \Iterator
147147 TrinaryLogic::createNo (),
148148 ];
149149
150- $ intersectionTypeB = new IntersectionType ([
151- new IntegerType (),
152- ]);
153-
154- yield [
155- $ intersectionTypeB ,
156- $ intersectionTypeB ,
157- TrinaryLogic::createYes (),
158- ];
159-
160150 yield [
161151 new IntersectionType ([
162152 new ArrayType (new MixedType (), new MixedType ()),
@@ -335,16 +325,6 @@ public function dataIsSubTypeOf(): \Iterator
335325 TrinaryLogic::createNo (),
336326 ];
337327
338- $ intersectionTypeB = new IntersectionType ([
339- new IntegerType (),
340- ]);
341-
342- yield [
343- $ intersectionTypeB ,
344- $ intersectionTypeB ,
345- TrinaryLogic::createYes (),
346- ];
347-
348328 $ intersectionTypeC = new IntersectionType ([
349329 new StringType (),
350330 new CallableType (),
Original file line number Diff line number Diff line change @@ -1825,7 +1825,7 @@ public function dataUnion(): array
18251825 [
18261826 [
18271827 new UnionType ([
1828- new IntersectionType ([ new ArrayType (new MixedType (), new MixedType ())] ),
1828+ new ArrayType (new MixedType (), new MixedType ()),
18291829 IntegerRangeType::fromInterval (null , -1 ),
18301830 IntegerRangeType::fromInterval (1 , null ),
18311831 ]),
@@ -1842,7 +1842,7 @@ public function dataUnion(): array
18421842 [
18431843 [
18441844 new UnionType ([
1845- new IntersectionType ([ new ArrayType (new MixedType (), new MixedType ())] ),
1845+ new ArrayType (new MixedType (), new MixedType ()),
18461846 new CallableType (),
18471847 ]),
18481848 TemplateTypeFactory::create (
You can’t perform that action at this time.
0 commit comments