5
5
use PHPStan \Reflection \ClassReflection ;
6
6
use PHPStan \Reflection \PropertiesClassReflectionExtension ;
7
7
use PHPStan \Reflection \PropertyReflection ;
8
+ use PHPStan \TrinaryLogic ;
9
+ use PHPStan \Type \ObjectType ;
8
10
9
11
/**
10
12
* Allows field access via magic methods
@@ -32,7 +34,7 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
32
34
// Content entities have magical __get... so it is kind of true.
33
35
return true ;
34
36
}
35
- if ($ reflection-> implementsInterface ( ' Drupal\Core\Field\FieldItemListInterface ' )) {
37
+ if (self :: classObjectIsSuperOfFieldItemList ( $ reflection)-> yes ( )) {
36
38
return FieldItemListPropertyReflection::canHandleProperty ($ classReflection , $ propertyName );
37
39
}
38
40
@@ -45,10 +47,22 @@ public function getProperty(ClassReflection $classReflection, string $propertyNa
45
47
if ($ reflection ->implementsInterface ('Drupal\Core\Entity\EntityInterface ' )) {
46
48
return new EntityFieldReflection ($ classReflection , $ propertyName );
47
49
}
48
- if ($ reflection-> implementsInterface ( ' Drupal\Core\Field\FieldItemListInterface ' )) {
50
+ if (self :: classObjectIsSuperOfFieldItemList ( $ reflection)-> yes ( )) {
49
51
return new FieldItemListPropertyReflection ($ classReflection , $ propertyName );
50
52
}
51
53
52
54
throw new \LogicException ($ classReflection ->getName () . ":: $ propertyName should be handled earlier. " );
53
55
}
56
+
57
+ protected static function classObjectIsSuperOfFieldItemList (\ReflectionClass $ reflection ) : TrinaryLogic
58
+ {
59
+ $ classObject = new ObjectType ($ reflection ->getName ());
60
+ $ interfaceObject = self ::getFieldItemListInterfaceObject ();
61
+ return $ interfaceObject ->isSuperTypeOf ($ classObject );
62
+ }
63
+
64
+ protected static function getFieldItemListInterfaceObject () : ObjectType
65
+ {
66
+ return new ObjectType ('Drupal\Core\Field\FieldItemListInterface ' );
67
+ }
54
68
}
0 commit comments