phpstan-drupal
phpstan-drupal copied to clipboard
How to handle type inferencing for $entity->get('field_ref')->entity?
I've got a custom ContentEntity with the following:
/**
* {@inheritdoc}
*/
public function getOrderItem(): ?OrderItemInterface {
return $this->get('order_item')->entity;
}
and PHPStan level 3 is spitting out
Method Drupal\hc_commerce_transfer\Entity\CommerceTransferItem::getOrderItem() should return Drupal\commerce_order\Entity\OrderItemInterface|null but returns Drupal\Core\Entity\ContentEntityInterface.
Is there a recommended way of handling this? All I can figure is to either use @phpstan-ignore or to add an ignore rule for the pattern, but those don't seem ideal.