2
2
3
3
namespace mglaman \PHPStanDrupal \Reflection ;
4
4
5
+ use PHPStan \BetterReflection \Reflection \ReflectionClass ;
5
6
use PHPStan \Reflection \ClassReflection ;
6
7
use PHPStan \Reflection \PropertiesClassReflectionExtension ;
7
8
use PHPStan \Reflection \PropertyReflection ;
@@ -28,16 +29,15 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
28
29
return false ;
29
30
}
30
31
31
- $ reflection = $ classReflection ->getNativeReflection ();
32
32
// We need to find a way to parse the entity annotation so that at the minimum the `entity_keys` are
33
33
// supported. The real fix is Drupal developers _really_ need to start writing @property definitions in the
34
34
// class doc if they don't get `get` methods.
35
- if ($ reflection ->implementsInterface ('Drupal\Core\Entity\ContentEntityInterface ' )) {
35
+ if ($ classReflection ->implementsInterface ('Drupal\Core\Entity\ContentEntityInterface ' )) {
36
36
// @todo revisit if it's a good idea to be true.
37
37
// Content entities have magical __get... so it is kind of true.
38
38
return true ;
39
39
}
40
- if (self ::classObjectIsSuperOfInterface ($ reflection , self ::getFieldItemListInterfaceObject ())->yes ()) {
40
+ if (self ::classObjectIsSuperOfInterface ($ classReflection -> getName () , self ::getFieldItemListInterfaceObject ())->yes ()) {
41
41
return FieldItemListPropertyReflection::canHandleProperty ($ classReflection , $ propertyName );
42
42
}
43
43
@@ -46,21 +46,19 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
46
46
47
47
public function getProperty (ClassReflection $ classReflection , string $ propertyName ): PropertyReflection
48
48
{
49
- $ reflection = $ classReflection ->getNativeReflection ();
50
- if ($ reflection ->implementsInterface ('Drupal\Core\Entity\EntityInterface ' )) {
49
+ if ($ classReflection ->implementsInterface ('Drupal\Core\Entity\EntityInterface ' )) {
51
50
return new EntityFieldReflection ($ classReflection , $ propertyName );
52
51
}
53
- if (self ::classObjectIsSuperOfInterface ($ reflection , self ::getFieldItemListInterfaceObject ())->yes ()) {
52
+ if (self ::classObjectIsSuperOfInterface ($ classReflection -> getName () , self ::getFieldItemListInterfaceObject ())->yes ()) {
54
53
return new FieldItemListPropertyReflection ($ classReflection , $ propertyName );
55
54
}
56
55
57
56
throw new \LogicException ($ classReflection ->getName () . ":: $ propertyName should be handled earlier. " );
58
57
}
59
58
60
- public static function classObjectIsSuperOfInterface (\ ReflectionClass $ reflection , ObjectType $ interfaceObject ) : TrinaryLogic
59
+ public static function classObjectIsSuperOfInterface (string $ name , ObjectType $ interfaceObject ) : TrinaryLogic
61
60
{
62
- $ classObject = new ObjectType ($ reflection ->getName ());
63
- return $ interfaceObject ->isSuperTypeOf ($ classObject );
61
+ return $ interfaceObject ->isSuperTypeOf (new ObjectType ($ name ));
64
62
}
65
63
66
64
protected static function getFieldItemListInterfaceObject () : ObjectType
0 commit comments