From e4f4726fd97a7ae8b4dc4b49a423c0ac40ee4a3e Mon Sep 17 00:00:00 2001 From: Xurshudyan Date: Sun, 18 Aug 2024 18:28:42 +0400 Subject: [PATCH] Use match expression --- src/JobPayload.php | 38 +++++++++---------------- src/Repositories/RedisJobRepository.php | 22 ++++++-------- src/Tags.php | 19 +++++-------- 3 files changed, 29 insertions(+), 50 deletions(-) diff --git a/src/JobPayload.php b/src/JobPayload.php index 923753c1..50f76cd0 100644 --- a/src/JobPayload.php +++ b/src/JobPayload.php @@ -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', + }; } /** @@ -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, + }; } /** diff --git a/src/Repositories/RedisJobRepository.php b/src/Repositories/RedisJobRepository.php index 779e86c1..1f072ef6 100644 --- a/src/Repositories/RedisJobRepository.php +++ b/src/Repositories/RedisJobRepository.php @@ -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, + }; } /** diff --git a/src/Tags.php b/src/Tags.php index 3d571aa7..97a9dc83 100644 --- a/src/Tags.php +++ b/src/Tags.php @@ -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], + }; } /**