Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Feb 19, 2023
1 parent db436df commit abc2da9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
4 changes: 1 addition & 3 deletions src/Rules/PHPUnit/MockMethodCallRule.php
Expand Up @@ -6,7 +6,6 @@
use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Type\IntersectionType;
use PHPUnit\Framework\MockObject\Builder\InvocationMocker;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\MockObject\Stub;
Expand Down Expand Up @@ -51,8 +50,7 @@ public function processNode(Node $node, Scope $scope): array
$type = $scope->getType($node->var);

if (
$type instanceof IntersectionType
&& (
(
in_array(MockObject::class, $type->getObjectClassNames(), true)
|| in_array(Stub::class, $type->getObjectClassNames(), true)
)
Expand Down
16 changes: 3 additions & 13 deletions src/Type/PHPUnit/MockObjectDynamicReturnTypeExtension.php
Expand Up @@ -7,7 +7,6 @@
use PHPStan\Reflection\MethodReflection;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\Generic\GenericObjectType;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPUnit\Framework\MockObject\Builder\InvocationMocker;
Expand All @@ -32,24 +31,15 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
{
$type = $scope->getType($methodCall->var);
if (!($type instanceof IntersectionType)) {
return new ObjectType(InvocationMocker::class);
}

$mockClasses = array_values(array_filter($type->getTypes(), static function (Type $type): bool {
$classNames = $type->getObjectClassNames();
if (count($classNames) !== 1) {
return true;
}

return $classNames[0] !== MockObject::class;
$mockClasses = array_values(array_filter($type->getObjectClassNames(), static function (string $class): bool {
return $class !== MockObject::class;
}));

if (count($mockClasses) !== 1) {
return new ObjectType(InvocationMocker::class);
}

return new GenericObjectType(InvocationMocker::class, $mockClasses);
return new GenericObjectType(InvocationMocker::class, [new ObjectType($mockClasses[0])]);
}

}

0 comments on commit abc2da9

Please sign in to comment.