Skip to content

Commit ab783a8

Browse files
committed
Improved MockObjectDynamicReturnTypeExtension
1 parent 74c1c5f commit ab783a8

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/Type/PHPUnit/MockObjectDynamicReturnTypeExtension.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPStan\Reflection\MethodReflection;
88
use PHPStan\Type\Generic\GenericObjectType;
99
use PHPStan\Type\IntersectionType;
10+
use PHPStan\Type\ObjectType;
1011
use PHPStan\Type\Type;
1112
use PHPStan\Type\TypeWithClassName;
1213
use PHPUnit\Framework\MockObject\Builder\InvocationMocker;
@@ -29,12 +30,16 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
2930
{
3031
$type = $scope->getType($methodCall->var);
3132
if (!($type instanceof IntersectionType)) {
32-
return new GenericObjectType(InvocationMocker::class, []);
33+
return new ObjectType(InvocationMocker::class);
3334
}
3435

35-
$mockClasses = array_filter($type->getTypes(), function (Type $type): bool {
36+
$mockClasses = array_values(array_filter($type->getTypes(), function (Type $type): bool {
3637
return !$type instanceof TypeWithClassName || $type->getClassName() !== MockObject::class;
37-
});
38+
}));
39+
40+
if (count($mockClasses) !== 1) {
41+
return new ObjectType(InvocationMocker::class);
42+
}
3843

3944
return new GenericObjectType(InvocationMocker::class, $mockClasses);
4045
}

0 commit comments

Comments
 (0)