phpdoc如何记录@return的成功和失败

时间:2017-06-21 10:51:52

标签: php phpdoc docblocks

我试图保持我的php rest服务器正常文档,所以我想知道我们如何记录返回值可以是2之一?

  /**
   * send email to a user that contain reset data
   * it also create reset token, so if there was an old reset token it will be changed
   *
   * @param email $email {@type email"
   * @return SuccessMessage|FailMessage
   */
  public function getSearch($email){
   // search for $email, if success return 
   if($this->doOperation()===true){
     return new SuccessMessage($email);
   }

   return new FailMessage($email);
  }

现在说FailMessage和SuccessMessage都只是一个空类来充当一致的数据结构

更像这样的东西。

class FailMessage extends Messages{
  function __construct(string $message, int $uid) {
      if(is_callable("parent::__construct")){
        parent::__construct(...func_get_args());
      }
      $this->uid = $uid;
      $this->message = $data;
   }
}

1 个答案:

答案 0 :(得分:2)

  /**
   * send email to a user that contain reset data
   * it also create reset token, so if there was an old reset token it will be changed
   *
   * @param email $email {@type email"
   * @return object SuccessMessage|FailMessage
   */

您自己的评论是好的但是您可以添加更多对象类型。另请阅读官方网站上的以下文件:

returnTags-PHPDoc

相关问题