22
33namespace PHPStan \Type \PHPUnit ;
44
5+ use PhpParser \Node \Arg ;
56use PhpParser \Node \Expr \MethodCall ;
7+ use PhpParser \Node \Expr \StaticCall ;
68use PHPStan \Analyser \Scope ;
79use PHPStan \Reflection \MethodReflection ;
810use PHPStan \Type \DynamicMethodReturnTypeExtension ;
11+ use PHPStan \Type \DynamicStaticMethodReturnTypeExtension ;
912use PHPStan \Type \ObjectType ;
1013use PHPStan \Type \Type ;
1114use PHPStan \Type \TypeCombinator ;
1215use PHPUnit \Framework \MockObject \MockObject ;
1316use PHPUnit \Framework \MockObject \Stub ;
1417use PHPUnit \Framework \TestCase ;
1518use function count ;
16- use function in_array ;
19+ use function strtolower ;
1720
18- class MockForIntersectionDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
21+ class MockForIntersectionDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension, DynamicStaticMethodReturnTypeExtension
1922{
2023
2124 public function getClass (): string
@@ -25,19 +28,29 @@ public function getClass(): string
2528
2629 public function isMethodSupported (MethodReflection $ methodReflection ): bool
2730 {
28- return in_array (
29- $ methodReflection ->getName (),
30- [
31- 'createMockForIntersectionOfInterfaces ' ,
32- 'createStubForIntersectionOfInterfaces ' ,
33- ],
34- true ,
35- );
31+ return strtolower ($ methodReflection ->getName ()) === 'createmockforintersectionofinterfaces ' ;
32+ }
33+
34+ public function isStaticMethodSupported (MethodReflection $ methodReflection ): bool
35+ {
36+ return strtolower ($ methodReflection ->getName ()) === 'createstubforintersectionofinterfaces ' ;
37+ }
38+
39+ public function getTypeFromStaticMethodCall (MethodReflection $ methodReflection , StaticCall $ methodCall , Scope $ scope ): ?Type
40+ {
41+ return $ this ->getTypeFromCall ($ methodReflection , $ methodCall ->getArgs (), $ scope );
3642 }
3743
3844 public function getTypeFromMethodCall (MethodReflection $ methodReflection , MethodCall $ methodCall , Scope $ scope ): ?Type
3945 {
40- $ args = $ methodCall ->getArgs ();
46+ return $ this ->getTypeFromCall ($ methodReflection , $ methodCall ->getArgs (), $ scope );
47+ }
48+
49+ /**
50+ * @param array<Arg> $args
51+ */
52+ private function getTypeFromCall (MethodReflection $ methodReflection , array $ args , Scope $ scope ): ?Type
53+ {
4154 if (!isset ($ args [0 ])) {
4255 return null ;
4356 }
0 commit comments