Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Type/PHPUnit/GetMockBuilderDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@

use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeWithClassName;

class GetMockBuilderDynamicReturnTypeExtension implements \PHPStan\Type\DynamicMethodReturnTypeExtension
class GetMockBuilderDynamicReturnTypeExtension implements \PHPStan\Type\DynamicMethodReturnTypeExtension, \PHPStan\Reflection\BrokerAwareExtension
{

/** @var \PHPStan\Broker\Broker */
private $broker;

public function setBroker(Broker $broker): void
{
$this->broker = $broker;
}

public function getClass(): string
{
return 'PHPUnit\Framework\TestCase';
Expand All @@ -37,6 +46,9 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method

$class = $argType->getValue();

if (!$this->broker->hasClass($class)) {
return $mockBuilderType;
}
if (!$mockBuilderType instanceof TypeWithClassName) {
throw new \PHPStan\ShouldNotHappenException();
}
Expand Down