refactor(scheduled-task): simplify server() with nullsafe operators and add return type

Replace nested null checks with nullsafe operator chains, add ?Server
return type, drop unreachable database branch, and cover all paths with
feature tests.
This commit is contained in:
Andras Bacsai committed 2026-05-04 12:26:15 +02:00
1 parent 8e22ce4ba7
commit 1849b5903e
2 files changed
+72 -12

No files matched your search

+6 -12
View File
@@ -76,20 +76,14 @@ class ScheduledTask extends BaseModel
return $this->hasMany(ScheduledTaskExecution::class)->orderBy('created_at', 'desc');
}
public function server()
public function server(): ?Server
{
if ($this->application) {
if ($this->application->destination && $this->application->destination->server) {
return $this->application->destination->server;
}
} elseif ($this->service) {
if ($this->service->destination && $this->service->destination->server) {
return $this->service->destination->server;
}
} elseif ($this->database) {
if ($this->database->destination && $this->database->destination->server) {
return $this->database->destination->server;
}
return $this->application->destination?->server;
}
if ($this->service) {
return $this->service->destination?->server;
}
return null;