Skip to content

Commit

Permalink
Use match expression (#1487)
Browse files Browse the repository at this point in the history
Co-authored-by: Xurshudyan <[email protected]>
  • Loading branch information
xurshudyan and Xurshudyan authored Aug 19, 2024
1 parent bcd523b commit 6080df7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 50 deletions.
38 changes: 14 additions & 24 deletions src/JobPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,13 @@ public function prepare($job)
*/
protected function determineType($job)
{
switch (true) {
case $job instanceof BroadcastEvent:
return 'broadcast';
case $job instanceof CallQueuedListener:
return 'event';
case $job instanceof SendQueuedMailable:
return 'mail';
case $job instanceof SendQueuedNotifications:
return 'notification';
default:
return 'job';
}
return match (true) {
$job instanceof BroadcastEvent => 'broadcast',
$job instanceof CallQueuedListener => 'event',
$job instanceof SendQueuedMailable => 'mail',
$job instanceof SendQueuedNotifications => 'notification',
default => 'job',
};
}

/**
Expand Down Expand Up @@ -169,18 +164,13 @@ protected function shouldBeSilenced($job)
*/
protected function underlyingJob($job)
{
switch (true) {
case $job instanceof BroadcastEvent:
return $job->event;
case $job instanceof CallQueuedListener:
return $job->class;
case $job instanceof SendQueuedMailable:
return $job->mailable;
case $job instanceof SendQueuedNotifications:
return $job->notification;
default:
return $job;
}
return match (true) {
$job instanceof BroadcastEvent => $job->event,
$job instanceof CallQueuedListener => $job->class,
$job instanceof SendQueuedMailable => $job->mailable,
$job instanceof SendQueuedNotifications => $job->notification,
default => $job,
};
}

/**
Expand Down
22 changes: 8 additions & 14 deletions src/Repositories/RedisJobRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,20 +273,14 @@ protected function countJobsByType($type)
*/
protected function minutesForType($type)
{
switch ($type) {
case 'failed_jobs':
return $this->failedJobExpires;
case 'recent_failed_jobs':
return $this->recentFailedJobExpires;
case 'pending_jobs':
return $this->pendingJobExpires;
case 'completed_jobs':
return $this->completedJobExpires;
case 'silenced_jobs':
return $this->completedJobExpires;
default:
return $this->recentJobExpires;
}
return match ($type) {
'failed_jobs' => $this->failedJobExpires,
'recent_failed_jobs' => $this->recentFailedJobExpires,
'pending_jobs' => $this->pendingJobExpires,
'completed_jobs' => $this->completedJobExpires,
'silenced_jobs' => $this->completedJobExpires,
default => $this->recentJobExpires,
};
}

/**
Expand Down
19 changes: 7 additions & 12 deletions src/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,13 @@ protected static function explicitTags(array $jobs)
*/
public static function targetsFor($job)
{
switch (true) {
case $job instanceof BroadcastEvent:
return [$job->event];
case $job instanceof CallQueuedListener:
return [static::extractEvent($job)];
case $job instanceof SendQueuedMailable:
return [$job->mailable];
case $job instanceof SendQueuedNotifications:
return [$job->notification];
default:
return [$job];
}
return match (true) {
$job instanceof BroadcastEvent => [$job->event],
$job instanceof CallQueuedListener => [static::extractEvent($job)],
$job instanceof SendQueuedMailable => [$job->mailable],
$job instanceof SendQueuedNotifications => [$job->notification],
default => [$job],
};
}

/**
Expand Down

0 comments on commit 6080df7

Please sign in to comment.