2
2
3
3
namespace PHPStan \Type \Doctrine \Descriptors ;
4
4
5
- use PHPStan \ Broker \ Broker ;
5
+ use Doctrine \ DBAL \ Platforms \ AbstractPlatform ;
6
6
use PHPStan \Reflection \ParametersAcceptorSelector ;
7
+ use PHPStan \Reflection \ReflectionProvider ;
7
8
use PHPStan \Type \MixedType ;
9
+ use PHPStan \Type \ObjectType ;
8
10
use PHPStan \Type \Type ;
9
11
use PHPStan \Type \TypeCombinator ;
10
12
@@ -14,16 +16,16 @@ class ReflectionDescriptor implements DoctrineTypeDescriptor
14
16
/** @var class-string<\Doctrine\DBAL\Types\Type> */
15
17
private $ type ;
16
18
17
- /** @var Broker */
18
- private $ broker ;
19
+ /** @var ReflectionProvider */
20
+ private $ reflectionProvider ;
19
21
20
22
/**
21
23
* @param class-string<\Doctrine\DBAL\Types\Type> $type
22
24
*/
23
- public function __construct (string $ type , Broker $ broker )
25
+ public function __construct (string $ type , ReflectionProvider $ reflectionProvider )
24
26
{
25
27
$ this ->type = $ type ;
26
- $ this ->broker = $ broker ;
28
+ $ this ->reflectionProvider = $ reflectionProvider ;
27
29
}
28
30
29
31
public function getType (): string
@@ -33,14 +35,22 @@ public function getType(): string
33
35
34
36
public function getWritableToPropertyType (): Type
35
37
{
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 ();
37
43
38
44
return TypeCombinator::removeNull ($ type );
39
45
}
40
46
41
47
public function getWritableToDatabaseType (): Type
42
48
{
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 ();
44
54
45
55
return TypeCombinator::removeNull ($ type );
46
56
}
0 commit comments