Bug report
When I use an inline @var doc to describe an entity which was only type-hinted from the entity interface, phpstan says the entity class is not a subtype of the entity interface.
This happens with Drupal entity classes, but not with regular old classes and interfaces like \Reflector and \ReflectionClass.
So I suspect it is a side effect from phpstan-drupal.
Code snippet that reproduces the problem
use Drupal\node\NodeInterface;
class C {
/**
* @param \Drupal\node\NodeInterface $node
*
* @return mixed
*/
public function foo(NodeInterface $node): mixed {
/** @var \Drupal\node\Entity\Node $node */
return $node;
}
}
------ ------------------------------------------------------------------------------------------------------------
Line src/Service/AdvancedEntityAutocompleteMatcher.php
------ ------------------------------------------------------------------------------------------------------------
** PHPDoc tag @var with type Drupal\node\Entity\Node is not subtype of native type Drupal\node\NodeInterface.
🪪 varTag.nativeType
------ ------------------------------------------------------------------------------------------------------------
Why would I do this?
I have a project with some magic __set() assign like $entity->x = $y. The entity is type-hinted using an entity interface, and phpstan (level 2) complains that the property does not exist.
For now I want a stop-gap solution that makes phpstan happy but does not change the code itself, because this part is not really tested yet.
Bug report
When I use an inline
@vardoc to describe an entity which was only type-hinted from the entity interface, phpstan says the entity class is not a subtype of the entity interface.This happens with Drupal entity classes, but not with regular old classes and interfaces like
\Reflectorand\ReflectionClass.So I suspect it is a side effect from phpstan-drupal.
Code snippet that reproduces the problem
Why would I do this?
I have a project with some magic __set() assign like
$entity->x = $y. The entity is type-hinted using an entity interface, and phpstan (level 2) complains that the property does not exist.For now I want a stop-gap solution that makes phpstan happy but does not change the code itself, because this part is not really tested yet.