Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Reflection/FieldItemListPropertyReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PHPStan\Type\ObjectType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use PHPStan\Type\UnionType;
use function in_array;

/**
Expand Down Expand Up @@ -42,7 +43,7 @@ public static function canHandleProperty(ClassReflection $classReflection, strin
public function getReadableType(): Type
{
if ($this->propertyName === 'entity') {
return new ObjectType('Drupal\Core\Entity\EntityInterface');
return new UnionType([new ObjectType('Drupal\Core\Entity\EntityInterface'), new NullType()]);
}
if ($this->propertyName === 'target_id') {
// @todo needs to be union type.
Expand All @@ -60,7 +61,7 @@ public function getReadableType(): Type
public function getWritableType(): Type
{
if ($this->propertyName === 'entity') {
return new ObjectType('Drupal\Core\Entity\EntityInterface');
return new UnionType([new ObjectType('Drupal\Core\Entity\EntityInterface'), new NullType()]);
}
if ($this->propertyName === 'target_id') {
return new StringType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\StringType;
use PHPStan\Type\VerbosityLevel;

final class EntityFieldsViaMagicReflectionExtensionTest extends PHPStanTestCase {

Expand Down Expand Up @@ -119,7 +120,7 @@ public function testGetPropertyFieldItemList(): void
self::assertInstanceOf(StringType::class, $readableType);
$propertyReflection = $this->extension->getProperty($classReflection, 'entity');
$readableType = $propertyReflection->getReadableType();
self::assertInstanceOf(ObjectType::class, $readableType);
self::assertSame('Drupal\Core\Entity\EntityInterface|null', $readableType->describe(VerbosityLevel::typeOnly()));
$propertyReflection = $this->extension->getProperty($classReflection, 'format');
$readableType = $propertyReflection->getReadableType();
self::assertInstanceOf(NullType::class, $readableType);
Expand Down
Loading