Skip to content

Commit 0adecb3

Browse files
committed
优化代码
1 parent aaa2d9a commit 0adecb3

File tree

2 files changed

+80
-8
lines changed

2 files changed

+80
-8
lines changed

src/Contract/IMessage.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface IMessage extends IArrayable
1111
/**
1212
* 获取消息 ID
1313
*
14-
* @return string
14+
* @return string|null
1515
*/
1616
public function getMessageId(): string;
1717

@@ -28,7 +28,7 @@ public function setMessageId(string $messageId);
2828
*
2929
* @return string
3030
*/
31-
public function getMessage(): string;
31+
public function getMessage(): ?string;
3232

3333
/**
3434
* 设置消息内容
@@ -53,6 +53,36 @@ public function getWorkingTimeout(): float;
5353
*/
5454
public function setWorkingTimeout(float $workingTimeout);
5555

56+
/**
57+
* 获取已重试次数
58+
*
59+
* @return integer
60+
*/
61+
public function getRetryCount(): int;
62+
63+
/**
64+
* 获取重试次数
65+
*
66+
* @param integer $retryCount
67+
* @return void
68+
*/
69+
public function setRetryCount(int $retryCount);
70+
71+
/**
72+
* 获取最大重试次数
73+
*
74+
* @return integer
75+
*/
76+
public function getMaxRetryCount(): int;
77+
78+
/**
79+
* 获取最大重试次数
80+
*
81+
* @param integer $maxRetryCount
82+
* @return void
83+
*/
84+
public function setMaxRetryCount(int $maxRetryCount);
85+
5686
/**
5787
* 从数组加载数据
5888
*

src/Model/Message.php

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Message implements IMessage
1313
*
1414
* @var string
1515
*/
16-
protected $messageId;
16+
protected $messageId = '';
1717

1818
/**
1919
* 已重试次数
@@ -106,18 +106,60 @@ public function setWorkingTimeout(float $workingTimeout)
106106
$this->workingTimeout = $workingTimeout;
107107
}
108108

109+
/**
110+
* 获取已重试次数
111+
*
112+
* @return integer
113+
*/
114+
public function getRetryCount(): int
115+
{
116+
return $this->retryCount;
117+
}
118+
119+
/**
120+
* 获取重试次数
121+
*
122+
* @param integer $retryCount
123+
* @return void
124+
*/
125+
public function setRetryCount(int $retryCount)
126+
{
127+
$this->retryCount = $retryCount;
128+
}
129+
130+
/**
131+
* 获取最大重试次数
132+
*
133+
* @return integer
134+
*/
135+
public function getMaxRetryCount(): int
136+
{
137+
return $this->maxRetryCount;
138+
}
139+
140+
/**
141+
* 获取最大重试次数
142+
*
143+
* @param integer $maxRetryCount
144+
* @return void
145+
*/
146+
public function setMaxRetryCount(int $maxRetryCount)
147+
{
148+
$this->maxRetryCount = $maxRetryCount;
149+
}
150+
109151
/**
110152
* 将当前对象作为数组返回
111153
* @return array
112154
*/
113155
public function toArray(): array
114156
{
115157
return [
116-
'messageId' => $this->messageId,
117-
'retryCount' => $this->retryCount,
118-
'maxRetryCount' => $this->maxRetryCount,
119-
'message' => $this->message,
120-
'workingTimeout'=> $this->workingTimeout,
158+
'messageId' => $this->getMessageId(),
159+
'retryCount' => $this->getRetryCount(),
160+
'maxRetryCount' => $this->getMaxRetryCount(),
161+
'message' => $this->getMessage(),
162+
'workingTimeout'=> $this->getWorkingTimeout(),
121163
];
122164
}
123165

0 commit comments

Comments
 (0)