php - 用于在闭包中抛出异常的 PHPDoc
问题描述
是否有任何聪明的方法来记录闭包引发异常?我正在使用 PhpStorm,我想摆脱烦人的警告,即在给定的块中永远不会引发异常。
该方法createFromState()
是抛出和AbstractEntityRepositoryException
异常,我想让IDE知道它。
/**
* Closure used to create an object from repository.
* The default implementation is using the method {@link EntityRepositoryInterface::createFromState()}
*
* @var Closure|null
* @throws AbstractEntityRepositoryException
*/
private ?Closure $create = null;
public function __construct(ControllerInteface $controller, string $id, ?Closure $create = null)
{
parent::__construct($controller, $id);
if ($create === null) {
$this->create = static function (EntityRepositoryInterface $repository, FormModelInterface $model): Entity {
return $repository->createFromState($model->toState());
};
}
else {
$this->create = $create;
}
}
/**
* @param FormModelInterface $model
* @return Entity
* @throws CreateActionException
*/
public function saveModel(FormModelInterface $model): Entity
{
try {
$create = $this->create;
return $create($this->repository, $model);
} catch (AbstractEntityRepositoryException $e) {
throw new CreateActionException($e->getMessage(), $e->getErrors());
}
}
解决方案
PHP Storm 似乎还没有正确支持该注释。这个问题https://youtrack.jetbrains.com/issue/WI-52095正是我的情况。感谢您的帮助!我已将我的案例添加到上述票证中。
推荐阅读
- javascript - 如何在 arduino 中使用 javascript 代码并将 javascript 值分配给 arduino 值
- r - 如何在没有节点重叠的情况下制作更好的图表?
- c# - 如何在星形图案下方打印
- amazon-web-services - 从 rdb 恢复过期密钥重启 redis 服务器
- javascript - 在 InfoWindow 中添加更多信息
- kubernetes - 如何为 kubernetes 中的节点分配 gpus [使用 kubernetes-client java api]
- c - 如何将二进制数转换为有符号十进制数
- python - 通过加载和保存权重继续训练 Keras 模型
- ios - 如何在 iOS 的 TableView 中使用 AdMob 横幅广告?
- python-3.x - Pandas:如何仅遍历两个 ID 列的回溯日期以提供唯一 ID 和计数?