@@ -59,40 +59,43 @@ public function specifyTypes(
5959 );
6060 }
6161
62- $ hasMethodTypes = [];
63- foreach ($ methodNameTypes as $ methodNameType ) {
64- $ hasMethodTypes [] = new HasMethodType ($ methodNameType ->getValue ());
65- }
62+ $ specifiedTypes = new SpecifiedTypes ([], []);
6663
6764 $ objectType = $ scope ->getType ($ node ->getArgs ()[0 ]->value );
6865 if ($ objectType ->isString ()->yes ()) {
6966 if ($ objectType ->isClassString ()->yes ()) {
70- return $ this ->typeSpecifier ->create (
71- $ node ->getArgs ()[0 ]->value ,
72- new IntersectionType ([
73- $ objectType ,
74- ...$ hasMethodTypes ,
75- ]),
76- $ context ,
77- $ scope ,
78- );
67+ foreach ($ methodNameTypes as $ methodNameType ) {
68+ $ specifiedTypes = $ specifiedTypes ->unionWith ($ this ->typeSpecifier ->create (
69+ $ node ->getArgs ()[0 ]->value ,
70+ new IntersectionType ([
71+ $ objectType ,
72+ new HasMethodType ($ methodNameType ->getValue ()),
73+ ]),
74+ $ context ,
75+ $ scope ,
76+ ));
77+ }
7978 }
8079
81- return new SpecifiedTypes ([], []) ;
80+ return $ specifiedTypes ;
8281 }
8382
84- return $ this ->typeSpecifier ->create (
85- $ node ->getArgs ()[0 ]->value ,
86- new UnionType ([
87- new IntersectionType ([
88- new ObjectWithoutClassType (),
89- ...$ hasMethodTypes ,
83+ foreach ($ methodNameTypes as $ methodNameType ) {
84+ $ specifiedTypes = $ specifiedTypes ->unionWith ($ this ->typeSpecifier ->create (
85+ $ node ->getArgs ()[0 ]->value ,
86+ new UnionType ([
87+ new IntersectionType ([
88+ new ObjectWithoutClassType (),
89+ new HasMethodType ($ methodNameType ->getValue ()),
90+ ]),
91+ new ClassStringType (),
9092 ]),
91- new ClassStringType (),
92- ]),
93- $ context ,
94- $ scope ,
95- );
93+ $ context ,
94+ $ scope ,
95+ ));
96+ }
97+
98+ return $ specifiedTypes ;
9699 }
97100
98101}
0 commit comments