查找@throws异常:PHPDoc期望此方法有哪些异常?

时间:2018-07-07 04:56:37

标签: php datetime exception phpdoc

我有这个类方法,我的IDE(PHPStorm)通知我它缺少@throws tags in the PHPDoc

/**
 * Return Time Frame for request to API
 *
 * @since 2.4.7
 *
 * Default time_frame is two dates, start of current week, and four weeks from now.
 *
 * @return array or start and end dates as required for MBO API
 */
public function time_frame(){
    $start_time = new \Datetime( date_i18n('Y-m-d', current_time( 'timestamp' )) );
    $end_time = new \Datetime( date_i18n('Y-m-d', current_time( 'timestamp' )) );
    $di = new \DateInterval('P4W');
    $end_time->add($di);

    return array('StartDateTime'=> $start_time->format('Y-m-d'), 'EndDateTime'=> $end_time->format('Y-m-d'));
}

尽管我可能会为此函数抛出的exceptions用于DatetimeDateIntervalDateTime::__construct()DateInterval::__construct()

添加

* @throws DateTime::__construct()
* @throws DateInterval::__construct()

不满足验证者的要求。有什么建议么?

1 个答案:

答案 0 :(得分:2)

试图在文档上添加txtObj。根据\ DateTime类构造函数和DateInterval构造函数,如果某些参数未正确声明,则每个类都可能引发\ Exception。 DateTime的时区和DateInterval上的interval_spec的时区

参考:DatetTime::__construct reference