【发布时间】:2018-07-07 04:56:37
【问题描述】:
我有这个类方法,我的 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 用于Datetime 和DateInterval:DateTime::__construct()、DateInterval::__construct()。
添加
* @throws DateTime::__construct()
* @throws DateInterval::__construct()
不满足验证者。有什么建议么?
【问题讨论】:
-
你用的是什么php版本?
-
通常,throws 标签用于指示该方法将抛出什么异常,如果有的话。不是它使用的类会抛出什么
-
@Charis php7.1,或者可能是第 2 点。
标签: php datetime exception phpdoc