Created
February 5, 2020 13:41
-
-
Save canvural/f3d35fd72106a1140ec302de6e20f752 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Methods/EloquentBuilderForwardsCallsExtension.php b/src/Methods/EloquentBuilderForwardsCallsExtension.php | |
index cd212f3..35623d1 100644 | |
--- a/src/Methods/EloquentBuilderForwardsCallsExtension.php | |
+++ b/src/Methods/EloquentBuilderForwardsCallsExtension.php | |
@@ -16,6 +16,7 @@ use PHPStan\Reflection\MethodsClassReflectionExtension; | |
use PHPStan\Reflection\ParametersAcceptorSelector; | |
use PHPStan\ShouldNotHappenException; | |
use PHPStan\Type\Generic\GenericObjectType; | |
+use PHPStan\Type\Generic\TemplateMixedType; | |
use PHPStan\Type\MixedType; | |
use PHPStan\Type\ObjectType; | |
use PHPStan\Type\Type; | |
@@ -88,18 +89,24 @@ final class EloquentBuilderForwardsCallsExtension implements MethodsClassReflect | |
$templateTypeMap = $classReflection->getActiveTemplateTypeMap(); | |
- /** @var Type|ObjectType|null $modelType */ | |
+ /** @var Type|ObjectType|TemplateMixedType $modelType */ | |
$modelType = $templateTypeMap->getType('TModelClass'); | |
- if ($this->getBuilderReflection()->hasNativeMethod($methodName) && ($modelType === null || ! $modelType instanceof ObjectType)) { | |
+ if ($this->getBuilderReflection()->hasNativeMethod($methodName) && (! $modelType instanceof ObjectType)) { | |
$methodReflection = $this->getBuilderReflection()->getNativeMethod($methodName); | |
+ $builderClass = EloquentBuilder::class; | |
+ | |
+ if ($modelType instanceof TemplateMixedType) { | |
+ /** @var string $builderClass */ | |
+ $builderClass = $modelType->getScope()->getClassName(); | |
+ } | |
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants()); | |
return new EloquentBuilderMethodReflection( | |
$methodName, $classReflection, | |
$parametersAcceptor->getParameters(), | |
- new ObjectType(EloquentBuilder::class), | |
+ new GenericObjectType($builderClass, [$modelType]), | |
$parametersAcceptor->isVariadic() | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment