有什么聰明的方法來記錄閉包拋出異常嗎?我正在使用 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()); } }
添加回答
舉報
0/150
提交
取消