Skip to content

Commit dcf42b9

Browse files
committed
ReflectionDescriptor - fix compatibility with conditional return type in VarDateTimeImmutableType
1 parent 9a56b06 commit dcf42b9

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/Type/Doctrine/Descriptors/ReflectionDescriptor.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
namespace PHPStan\Type\Doctrine\Descriptors;
44

5+
use Doctrine\DBAL\Platforms\AbstractPlatform;
56
use PHPStan\Reflection\ParametersAcceptorSelector;
67
use PHPStan\Reflection\ReflectionProvider;
78
use PHPStan\Type\MixedType;
9+
use PHPStan\Type\ObjectType;
810
use PHPStan\Type\Type;
911
use PHPStan\Type\TypeCombinator;
1012

@@ -33,14 +35,22 @@ public function getType(): string
3335

3436
public function getWritableToPropertyType(): Type
3537
{
36-
$type = ParametersAcceptorSelector::selectSingle($this->reflectionProvider->getClass($this->type)->getNativeMethod('convertToPHPValue')->getVariants())->getReturnType();
38+
$method = $this->reflectionProvider->getClass($this->type)->getNativeMethod('convertToPHPValue');
39+
$type = ParametersAcceptorSelector::selectFromTypes([
40+
new MixedType(),
41+
new ObjectType(AbstractPlatform::class),
42+
], $method->getVariants(), false)->getReturnType();
3743

3844
return TypeCombinator::removeNull($type);
3945
}
4046

4147
public function getWritableToDatabaseType(): Type
4248
{
43-
$type = ParametersAcceptorSelector::selectSingle($this->reflectionProvider->getClass($this->type)->getNativeMethod('convertToDatabaseValue')->getVariants())->getParameters()[0]->getType();
49+
$method = $this->reflectionProvider->getClass($this->type)->getNativeMethod('convertToDatabaseValue');
50+
$type = ParametersAcceptorSelector::selectFromTypes([
51+
new MixedType(),
52+
new ObjectType(AbstractPlatform::class),
53+
], $method->getVariants(), false)->getParameters()[0]->getType();
4454

4555
return TypeCombinator::removeNull($type);
4656
}

0 commit comments

Comments
 (0)