用于在闭包中抛出异常的 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());

        }

    }


撒科打诨
浏览 131回答 1
1回答

汪汪一只猫

似乎 PHP Storm 还没有正确支持该注释。
打开App,查看更多内容
随时随地看视频慕课网APP