Skip to content

Commit 5391637

Browse files
committed
Use objectType instead
1 parent d6c0af9 commit 5391637

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/Reflection/EntityFieldsViaMagicReflectionExtension.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPStan\Reflection\ClassReflection;
66
use PHPStan\Reflection\PropertiesClassReflectionExtension;
77
use PHPStan\Reflection\PropertyReflection;
8+
use PHPStan\Type\ObjectType;
89

910
/**
1011
* Allows field access via magic methods
@@ -32,7 +33,7 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
3233
// Content entities have magical __get... so it is kind of true.
3334
return true;
3435
}
35-
if ($reflection->getName() === 'Drupal\Core\Field\FieldItemListInterface' || $reflection->implementsInterface('Drupal\Core\Field\FieldItemListInterface')) {
36+
if (self::classObjectIsSuperOfFieldItemList($reflection)) {
3637
return FieldItemListPropertyReflection::canHandleProperty($classReflection, $propertyName);
3738
}
3839

@@ -45,10 +46,22 @@ public function getProperty(ClassReflection $classReflection, string $propertyNa
4546
if ($reflection->implementsInterface('Drupal\Core\Entity\EntityInterface')) {
4647
return new EntityFieldReflection($classReflection, $propertyName);
4748
}
48-
if ($reflection->getName() === 'Drupal\Core\Field\FieldItemListInterface' || $reflection->implementsInterface('Drupal\Core\Field\FieldItemListInterface')) {
49+
if (self::classObjectIsSuperOfFieldItemList($reflection)) {
4950
return new FieldItemListPropertyReflection($classReflection, $propertyName);
5051
}
5152

5253
throw new \LogicException($classReflection->getName() . "::$propertyName should be handled earlier.");
5354
}
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+
}
5467
}

0 commit comments

Comments
 (0)