php - 注释:如何在 php 的 docblocks 中指定时间戳
问题描述
我有一个返回时间戳的方法。我想做这样的事情:
class MyAwesomeService {
/**
* @return array<int, timestamp>
*/
public function myAwesomeMethod(): array
{
return [
1636380000,
1636385555,
1636386666,
];
}
}
但是,我认为不@return array<int, timestamp>
成立。
在文档块中指定时间戳的有效格式是什么?
解决方案
您可以使用int[]
,时间戳没有有效值。但是,您可以创建一个 ValueObject。
class MyAwesomeService {
/**
* @return int[]
*/
public function myAwesomeMethod(): array
{
return [
1636380000,
1636385555,
1636386666,
];
}
}
如果您使用值对象:
final class Timestamp
{
private $timestamp;
public function __construct(int $timestamp) {
$this->timestamp = $timestamp;
}
public function get() : int
{
return $this->timestamp;
}
}
class MyAwesomeService {
/**
* @return Timestamp[]
*/
public function myAwesomeMethod(): array
{
return [
new Timestamp(1636380000),
new Timestamp(1636385555),
new Timestamp(1636386666),
];
}
}
推荐阅读
- rxjs - RXjs 6 使用 jasmine 进行回调测试
- python - django 我看不到我的表单
- groovy - groovy脚本正则表达式获取数字
- excel - 在 VBScript 中打开损坏的 Excel 文件
- ios - 带有大标题的 UINavigationBar 没有背景图片
- python - Python 2 to Python 3 futurize builtins str
- laravel - Laravel 控制器静态变量始终为空
- python-3.x - 没有名为 '__main__.demo' 的模块;'__main__' 不是 python3 包
- java - 如何检查元素何时从一个类移动到另一个类
- aws-lambda - AWS Lambda - 触发器选项卡在哪里?