Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Use match expression #1487

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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