Skip to content

Commit 6080df7

Browse files
xurshudyanXurshudyan
and
Xurshudyan
authored
Use match expression (#1487)
Co-authored-by: Xurshudyan <[email protected]>
1 parent bcd523b commit 6080df7

File tree

3 files changed

+29
-50
lines changed

3 files changed

+29
-50
lines changed

src/JobPayload.php

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,13 @@ public function prepare($job)
113113
*/
114114
protected function determineType($job)
115115
{
116-
switch (true) {
117-
case $job instanceof BroadcastEvent:
118-
return 'broadcast';
119-
case $job instanceof CallQueuedListener:
120-
return 'event';
121-
case $job instanceof SendQueuedMailable:
122-
return 'mail';
123-
case $job instanceof SendQueuedNotifications:
124-
return 'notification';
125-
default:
126-
return 'job';
127-
}
116+
return match (true) {
117+
$job instanceof BroadcastEvent => 'broadcast',
118+
$job instanceof CallQueuedListener => 'event',
119+
$job instanceof SendQueuedMailable => 'mail',
120+
$job instanceof SendQueuedNotifications => 'notification',
121+
default => 'job',
122+
};
128123
}
129124

130125
/**
@@ -169,18 +164,13 @@ protected function shouldBeSilenced($job)
169164
*/
170165
protected function underlyingJob($job)
171166
{
172-
switch (true) {
173-
case $job instanceof BroadcastEvent:
174-
return $job->event;
175-
case $job instanceof CallQueuedListener:
176-
return $job->class;
177-
case $job instanceof SendQueuedMailable:
178-
return $job->mailable;
179-
case $job instanceof SendQueuedNotifications:
180-
return $job->notification;
181-
default:
182-
return $job;
183-
}
167+
return match (true) {
168+
$job instanceof BroadcastEvent => $job->event,
169+
$job instanceof CallQueuedListener => $job->class,
170+
$job instanceof SendQueuedMailable => $job->mailable,
171+
$job instanceof SendQueuedNotifications => $job->notification,
172+
default => $job,
173+
};
184174
}
185175

186176
/**

src/Repositories/RedisJobRepository.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -273,20 +273,14 @@ protected function countJobsByType($type)
273273
*/
274274
protected function minutesForType($type)
275275
{
276-
switch ($type) {
277-
case 'failed_jobs':
278-
return $this->failedJobExpires;
279-
case 'recent_failed_jobs':
280-
return $this->recentFailedJobExpires;
281-
case 'pending_jobs':
282-
return $this->pendingJobExpires;
283-
case 'completed_jobs':
284-
return $this->completedJobExpires;
285-
case 'silenced_jobs':
286-
return $this->completedJobExpires;
287-
default:
288-
return $this->recentJobExpires;
289-
}
276+
return match ($type) {
277+
'failed_jobs' => $this->failedJobExpires,
278+
'recent_failed_jobs' => $this->recentFailedJobExpires,
279+
'pending_jobs' => $this->pendingJobExpires,
280+
'completed_jobs' => $this->completedJobExpires,
281+
'silenced_jobs' => $this->completedJobExpires,
282+
default => $this->recentJobExpires,
283+
};
290284
}
291285

292286
/**

src/Tags.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,13 @@ protected static function explicitTags(array $jobs)
9393
*/
9494
public static function targetsFor($job)
9595
{
96-
switch (true) {
97-
case $job instanceof BroadcastEvent:
98-
return [$job->event];
99-
case $job instanceof CallQueuedListener:
100-
return [static::extractEvent($job)];
101-
case $job instanceof SendQueuedMailable:
102-
return [$job->mailable];
103-
case $job instanceof SendQueuedNotifications:
104-
return [$job->notification];
105-
default:
106-
return [$job];
107-
}
96+
return match (true) {
97+
$job instanceof BroadcastEvent => [$job->event],
98+
$job instanceof CallQueuedListener => [static::extractEvent($job)],
99+
$job instanceof SendQueuedMailable => [$job->mailable],
100+
$job instanceof SendQueuedNotifications => [$job->notification],
101+
default => [$job],
102+
};
108103
}
109104

110105
/**

0 commit comments

Comments
 (0)