33namespace PHPStan \Type \PHPUnit ;
44
55use PhpParser \Node \Expr \MethodCall ;
6+ use PhpParser \Node \Expr \StaticCall ;
67use PHPStan \Analyser \Scope ;
78use PHPStan \Reflection \MethodReflection ;
89use PHPStan \Type \DynamicMethodReturnTypeExtension ;
10+ use PHPStan \Type \DynamicStaticMethodReturnTypeExtension ;
911use PHPStan \Type \ObjectType ;
1012use PHPStan \Type \Type ;
1113use PHPStan \Type \TypeCombinator ;
1214use PHPUnit \Framework \MockObject \MockObject ;
1315use PHPUnit \Framework \MockObject \Stub ;
1416use PHPUnit \Framework \TestCase ;
1517use function count ;
16- use function in_array ;
1718
18- class MockForIntersectionDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
19+ class MockForIntersectionDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension, DynamicStaticMethodReturnTypeExtension
1920{
2021
2122 public function getClass (): string
@@ -25,19 +26,26 @@ public function getClass(): string
2526
2627 public function isMethodSupported (MethodReflection $ methodReflection ): bool
2728 {
28- return in_array (
29- $ methodReflection ->getName (),
30- [
31- 'createMockForIntersectionOfInterfaces ' ,
32- 'createStubForIntersectionOfInterfaces ' ,
33- ],
34- true ,
35- );
29+ return 'createmockforintersectionofinterfaces ' === strtolower ($ methodReflection ->getName ());
30+ }
31+
32+ public function isStaticMethodSupported (MethodReflection $ methodReflection ): bool
33+ {
34+ return 'createstubforintersectionofinterfaces ' === strtolower ($ methodReflection ->getName ());
35+ }
36+
37+ public function getTypeFromStaticMethodCall (MethodReflection $ methodReflection , StaticCall $ methodCall , Scope $ scope ): ?Type
38+ {
39+ return $ this ->getTypeFromCall ($ methodReflection , $ methodCall ->getArgs (), $ scope );
3640 }
3741
3842 public function getTypeFromMethodCall (MethodReflection $ methodReflection , MethodCall $ methodCall , Scope $ scope ): ?Type
3943 {
40- $ args = $ methodCall ->getArgs ();
44+ return $ this ->getTypeFromCall ($ methodReflection , $ methodCall ->getArgs (), $ scope );
45+ }
46+
47+ private function getTypeFromCall (MethodReflection $ methodReflection , array $ args , Scope $ scope ): ?Type
48+ {
4149 if (!isset ($ args [0 ])) {
4250 return null ;
4351 }
0 commit comments