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