2
2
3
3
namespace PHPStan \Reflection ;
4
4
5
- use PHPStan \Type \IntegerType ;
6
- use PHPStan \Type \MixedType ;
5
+ use PHPStan \Type \NullType ;
7
6
use PHPStan \Type \ObjectType ;
7
+ use PHPStan \Type \StringType ;
8
8
use PHPStan \Type \Type ;
9
9
10
10
/**
@@ -27,25 +27,28 @@ public function __construct(ClassReflection $declaringClass, string $propertyNam
27
27
$ this ->propertyName = $ propertyName ;
28
28
}
29
29
30
- public static function canHandleProperty (string $ propertyName ): bool
30
+ public static function canHandleProperty (ClassReflection $ classReflection , string $ propertyName ): bool
31
31
{
32
+ // @todo use the class reflection and be more specific about handled properties.
33
+ // Currently \PHPStan\Reflection\EntityFieldReflection::getType always passes FieldItemListInterface.
32
34
$ names = ['entity ' , 'value ' , 'target_id ' ];
33
35
return in_array ($ propertyName , $ names , true );
34
36
}
35
37
36
38
public function getType (): Type
37
39
{
38
- if ($ this ->propertyName == 'entity ' ) {
39
- // It was a EntityReferenceFieldItemList
40
- return new ObjectType ('Drupal\Core\Entity\FieldableEntityInterface ' );
40
+ if ($ this ->propertyName === 'entity ' ) {
41
+ return new ObjectType ('Drupal\Core\Entity\EntityInterface ' );
41
42
}
42
- if ($ this ->propertyName == 'target_id ' ) {
43
- // It was a EntityReferenceFieldItemList
44
- return new IntegerType ();
43
+ if ($ this ->propertyName === 'target_id ' ) {
44
+ return new StringType ();
45
45
}
46
- if ($ this ->propertyName == 'value ' ) {
47
- return new MixedType ();
46
+ if ($ this ->propertyName === 'value ' ) {
47
+ return new StringType ();
48
48
}
49
+
50
+ // Fallback.
51
+ return new NullType ();
49
52
}
50
53
51
54
public function getDeclaringClass (): ClassReflection
0 commit comments