14
14
use PHPStan \Type \Accessory \HasMethodType ;
15
15
use PHPStan \Type \ClassStringType ;
16
16
use PHPStan \Type \Constant \ConstantBooleanType ;
17
- use PHPStan \Type \Constant \ConstantStringType ;
18
17
use PHPStan \Type \FunctionTypeSpecifyingExtension ;
19
18
use PHPStan \Type \IntersectionType ;
20
19
use PHPStan \Type \ObjectWithoutClassType ;
@@ -50,8 +49,8 @@ public function specifyTypes(
50
49
TypeSpecifierContext $ context ,
51
50
): SpecifiedTypes
52
51
{
53
- $ methodNameType = $ scope ->getType ($ node ->getArgs ()[1 ]->value );
54
- if (! $ methodNameType instanceof ConstantStringType ) {
52
+ $ methodNameTypes = $ scope ->getType ($ node ->getArgs ()[1 ]->value )-> getConstantStrings ( );
53
+ if ($ methodNameTypes === [] ) {
55
54
return $ this ->typeSpecifier ->create (
56
55
new FuncCall (new FullyQualified ('method_exists ' ), $ node ->getRawArgs ()),
57
56
new ConstantBooleanType (true ),
@@ -60,14 +59,19 @@ public function specifyTypes(
60
59
);
61
60
}
62
61
62
+ $ hasMethodTypes = [];
63
+ foreach ($ methodNameTypes as $ methodNameType ) {
64
+ $ hasMethodTypes [] = new HasMethodType ($ methodNameType ->getValue ());
65
+ }
66
+
63
67
$ objectType = $ scope ->getType ($ node ->getArgs ()[0 ]->value );
64
68
if ($ objectType ->isString ()->yes ()) {
65
69
if ($ objectType ->isClassString ()->yes ()) {
66
70
return $ this ->typeSpecifier ->create (
67
71
$ node ->getArgs ()[0 ]->value ,
68
72
new IntersectionType ([
69
73
$ objectType ,
70
- new HasMethodType ( $ methodNameType -> getValue ()) ,
74
+ ... $ hasMethodTypes ,
71
75
]),
72
76
$ context ,
73
77
$ scope ,
@@ -82,7 +86,7 @@ public function specifyTypes(
82
86
new UnionType ([
83
87
new IntersectionType ([
84
88
new ObjectWithoutClassType (),
85
- new HasMethodType ( $ methodNameType -> getValue ()) ,
89
+ ... $ hasMethodTypes ,
86
90
]),
87
91
new ClassStringType (),
88
92
]),
0 commit comments