Skip to content

Commit 60feadf

Browse files
committed
format code
1 parent a4f2380 commit 60feadf

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

src/Queue/CMQQueue.php

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function size($queue = null)
7373
{
7474
$attributes = $this->getQueue($queue)->get_attributes();
7575

76-
return (int) $attributes->activeMsgNum;
76+
return (int)$attributes->activeMsgNum;
7777
}
7878

7979
/**
@@ -106,7 +106,7 @@ public function push($job, $data = '', $queue = null)
106106
*
107107
* @param string $payload
108108
* @param string $queue
109-
* @param array $options
109+
* @param array $options
110110
*
111111
* @return mixed
112112
*/
@@ -117,40 +117,48 @@ public function pushRaw($payload, $queue = null, array $options = [])
117117
$driver = $this->parseQueue($queue);
118118

119119
if ($driver instanceof Topic) {
120-
$vTagList = [];
121-
if ($this->topicOptions['filter'] === self::CMQ_TOPIC_TAG_FILTER_NAME) {
122-
$vTagList = explode(',', $queue);
120+
switch ($this->topicOptions['filter']) {
121+
case self::CMQ_TOPIC_TAG_FILTER_NAME:
122+
return $driver->publish_message($message->msgBody, explode(',', $queue), null);
123+
case self::CMQ_TOPIC_ROUTING_FILTER_NAME:
124+
return $driver->publish_message($message->msgBody, [], $queue);
125+
default:
126+
throw new \InvalidArgumentException(
127+
'Invalid CMQ topic filter: ' . $this->topicOptions['filter']
128+
);
123129
}
124-
125-
$routingKey = null;
126-
if ($this->topicOptions['filter'] === self::CMQ_TOPIC_ROUTING_FILTER_NAME) {
127-
$routingKey = $queue;
128-
}
129-
130-
return $driver->publish_message($message->msgBody, $vTagList, $routingKey);
131130
}
132131

133-
return $driver->send_message($message, array_get($options, 'delay', 0));
132+
return $driver->send_message($message, Arr::get($options, 'delay', 0));
134133
}
135134

136135
/**
137136
* Push a new job onto the queue after a delay.
138137
*
139138
* @param \DateTimeInterface|\DateInterval|int $delay
140-
* @param string|object $job
141-
* @param mixed $data
142-
* @param string $queue
139+
* @param string|object $job
140+
* @param mixed $data
141+
* @param string $queue
143142
*
144143
* @return mixed
145144
*/
146145
public function later($delay, $job, $data = '', $queue = null)
147146
{
148-
$payload = $this->isPlain() ? $job->getPayload() : $this->createPayload($job, $data);
149-
150147
$delay = method_exists($this, 'getSeconds')
151148
? $this->getSeconds($delay)
152149
: $this->secondsUntil($delay);
153150

151+
if ($this->isPlain()) {
152+
return $this->pushRaw($job->getPayload(), $queue, ['delay' => $delay]);
153+
}
154+
155+
$reflection = new \ReflectionMethod($this, 'createPayload');
156+
if ($reflection->getNumberOfParameters() === 3) { // version >= 5.7
157+
$payload = $this->createPayload($job, $queue, $data);
158+
} else {
159+
$payload = $this->createPayload($job, $data);
160+
}
161+
154162
return $this->pushRaw($payload, $queue, ['delay' => $delay]);
155163
}
156164

@@ -167,10 +175,9 @@ public function pop($queue = null)
167175
$queue = $this->getQueue($queue);
168176
$message = $queue->receive_message($this->queueOptions['polling_wait_seconds']);
169177
} catch (CMQServerException $e) {
170-
if ($e->getCode() == self::CMQ_QUEUE_NO_MESSAGE_CODE) { //ignore no message
171-
return;
178+
if ((int)$e->getCode() === self::CMQ_QUEUE_NO_MESSAGE_CODE) { //ignore no message
179+
return null;
172180
}
173-
174181
throw $e;
175182
}
176183

@@ -211,13 +218,9 @@ public function getTopic($topic = null)
211218
public function parseQueue($queue = null)
212219
{
213220
if ($this->topicOptions['enable']) {
214-
$exchangeName = $this->topicOptions['name'] ?: $queue;
215-
216-
return $this->getTopic($exchangeName);
221+
return $this->getTopic($this->topicOptions['name'] ?: $queue);
217222
}
218223

219-
$queueName = $queue ?: $this->queueOptions['name'];
220-
221-
return $this->getQueue($queueName);
224+
return $this->getQueue($queue ?: $this->queueOptions['name']);
222225
}
223226
}

0 commit comments

Comments
 (0)