Skip to content

Commit

Permalink
Merge commit 'dcf42b9' into 1.3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Feb 18, 2023
2 parents 50383b9 + dcf42b9 commit f728e0d
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 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 PHPStan\Broker\Broker;
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 All @@ -14,16 +16,16 @@ class ReflectionDescriptor implements DoctrineTypeDescriptor
/** @var class-string<\Doctrine\DBAL\Types\Type> */
private $type;

/** @var Broker */
private $broker;
/** @var ReflectionProvider */
private $reflectionProvider;

/**
* @param class-string<\Doctrine\DBAL\Types\Type> $type
*/
public function __construct(string $type, Broker $broker)
public function __construct(string $type, ReflectionProvider $reflectionProvider)
{
$this->type = $type;
$this->broker = $broker;
$this->reflectionProvider = $reflectionProvider;
}

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

public function getWritableToPropertyType(): Type
{
$type = ParametersAcceptorSelector::selectSingle($this->broker->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->broker->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 f728e0d

Please sign in to comment.