我正在尝试将我的 phpstan 设置提升到第 3 级,但我收到如下错误:
Property Something::$repository (SpecificRepository) does not accept RepositoryInterface.
在一个看起来像这样的类上:
class Something
{
/** @var SpecificRepository */
protected $repository;
public function __construct(ORM $orm)
{
$this->orm = $orm;
$this->repository = $orm->getRepository(Something::class);
}
}
我知道我的 ORM 的getRepository
方法返回RepositoryInterface
,因为它不能更具体,但我需要@var
typehint 来告诉我的 IDE 工具和 phpstan,在这个类中,$repository
更具体地是一个SpecificRepository
. 我该怎么做?