From dcf42b98fbeb0bca246481b3a0e8f3d1c86f9b4a Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Sat, 18 Feb 2023 13:30:59 +0100 Subject: [PATCH] ReflectionDescriptor - fix compatibility with conditional return type in VarDateTimeImmutableType --- .../Doctrine/Descriptors/ReflectionDescriptor.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Type/Doctrine/Descriptors/ReflectionDescriptor.php b/src/Type/Doctrine/Descriptors/ReflectionDescriptor.php index 337591fb..283d9506 100644 --- a/src/Type/Doctrine/Descriptors/ReflectionDescriptor.php +++ b/src/Type/Doctrine/Descriptors/ReflectionDescriptor.php @@ -2,9 +2,11 @@ namespace PHPStan\Type\Doctrine\Descriptors; +use Doctrine\DBAL\Platforms\AbstractPlatform; use PHPStan\Reflection\ParametersAcceptorSelector; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\MixedType; +use PHPStan\Type\ObjectType; use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; @@ -33,14 +35,22 @@ public function getType(): string public function getWritableToPropertyType(): Type { - $type = ParametersAcceptorSelector::selectSingle($this->reflectionProvider->getClass($this->type)->getNativeMethod('convertToPHPValue')->getVariants())->getReturnType(); + $method = $this->reflectionProvider->getClass($this->type)->getNativeMethod('convertToPHPValue'); + $type = ParametersAcceptorSelector::selectFromTypes([ + new MixedType(), + new ObjectType(AbstractPlatform::class), + ], $method->getVariants(), false)->getReturnType(); return TypeCombinator::removeNull($type); } public function getWritableToDatabaseType(): Type { - $type = ParametersAcceptorSelector::selectSingle($this->reflectionProvider->getClass($this->type)->getNativeMethod('convertToDatabaseValue')->getVariants())->getParameters()[0]->getType(); + $method = $this->reflectionProvider->getClass($this->type)->getNativeMethod('convertToDatabaseValue'); + $type = ParametersAcceptorSelector::selectFromTypes([ + new MixedType(), + new ObjectType(AbstractPlatform::class), + ], $method->getVariants(), false)->getParameters()[0]->getType(); return TypeCombinator::removeNull($type); }