加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

是否可以为PHPDoc的调用方指定参数的显式类型

发布时间:2020-12-13 21:33:30 所属栏目:PHP教程 来源:网络整理
导读:有一个方法调用表达式: $session-setUser($this-em-getReference(UserAccount::class,$ownerId)); 其中setUser声明为 public function setUser(UserAccount $user): self $this- em- getReference是Doctrines的实体管理器方法返回对象| null. 因此,PhpStorm
有一个方法调用表达式:

$session->setUser($this->em->getReference(UserAccount::class,$ownerId));

其中setUser声明为

public function setUser(UserAccount $user): self

$this-> em-> getReference是Doctrines的实体管理器方法返回对象| null.

因此,PhpStorm将此调用标记为不匹配的参数 – 参数类型.

我当然可以将它分成2个语句并输入:

/** @var UserAccount $userAccount */
$userAccount = $this->em->getReference(UserAccount::class,$ownerId);
$session->setUser($userAccount);

但也许有办法内联吗?

解决方法

我很确定它可以用他们称之为 PHPStorm advanced metadata的东西.据我所知,你想要这样的东西(你可能需要试验)

override(DoctrineORMEntityManagerInterface::getReference(0),map([
    '' => '@'
]))

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读