Skip to content

Commit

Permalink
ReflectionDescriptor - fix compatibility with conditional return type…
Browse files Browse the repository at this point in the history
… in VarDateTimeImmutableType
  • Loading branch information
ondrejmirtes committed Feb 18, 2023
1 parent 9a56b06 commit dcf42b9
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Type/Doctrine/Descriptors/ReflectionDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit dcf42b9

Please sign in to comment.