22
33namespace PHPStan \Type \Doctrine \Descriptors ;
44
5- use PHPStan \ Broker \ Broker ;
5+ use Doctrine \ DBAL \ Platforms \ AbstractPlatform ;
66use PHPStan \Reflection \ParametersAcceptorSelector ;
7+ use PHPStan \Reflection \ReflectionProvider ;
78use PHPStan \Type \MixedType ;
9+ use PHPStan \Type \ObjectType ;
810use PHPStan \Type \Type ;
911use PHPStan \Type \TypeCombinator ;
1012
@@ -14,16 +16,16 @@ class ReflectionDescriptor implements DoctrineTypeDescriptor
1416 /** @var class-string<\Doctrine\DBAL\Types\Type> */
1517 private $ type ;
1618
17- /** @var Broker */
18- private $ broker ;
19+ /** @var ReflectionProvider */
20+ private $ reflectionProvider ;
1921
2022 /**
2123 * @param class-string<\Doctrine\DBAL\Types\Type> $type
2224 */
23- public function __construct (string $ type , Broker $ broker )
25+ public function __construct (string $ type , ReflectionProvider $ reflectionProvider )
2426 {
2527 $ this ->type = $ type ;
26- $ this ->broker = $ broker ;
28+ $ this ->reflectionProvider = $ reflectionProvider ;
2729 }
2830
2931 public function getType (): string
@@ -33,14 +35,22 @@ public function getType(): string
3335
3436 public function getWritableToPropertyType (): Type
3537 {
36- $ type = ParametersAcceptorSelector::selectSingle ($ this ->broker ->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 ->broker ->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