Skip to content

Commit 508b711

Browse files
committed
refactor: remove double nested behavior for early return
1 parent f515f05 commit 508b711

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

app/Http/Livewire/UpdatePlayerPanel.php

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,35 @@ public function render(): View
3434
$color = 'is-dark';
3535
$message = 'Profile was recently updated. Check back soon.';
3636
} else {
37-
if ($this->runUpdate) {
38-
try {
39-
DB::transaction(function () use ($cacheKey) {
40-
$cooldownMinutes = (int) config('services.halodotapi.cooldown');
37+
if (! $this->runUpdate) {
38+
return view('livewire.update-player-panel', [
39+
'color' => 'is-info',
40+
'message' => 'Checking for updated stats.'
41+
]);
42+
}
43+
44+
try {
45+
DB::transaction(function () use ($cacheKey) {
46+
$cooldownMinutes = (int)config('services.halodotapi.cooldown');
4147

42-
$this->player->updateFromHaloDotApi();
48+
$this->player->updateFromHaloDotApi();
49+
if (empty($this->player->xuid)) {
50+
$this->player->syncXuidFromXboxApi();
51+
$this->player->saveOrFail();
52+
}
4353

44-
// For some accounts, we don't have an xuid. We will grab them with this fallback
45-
if (empty($this->player->xuid)) {
46-
$this->player->syncXuidFromXboxApi();
47-
$this->player->saveOrFail();
48-
}
49-
Cache::put($cacheKey, true, now()->addMinutes($cooldownMinutes));
50-
$this->emitToRespectiveComponent();
51-
});
52-
} catch (RequestException $exception) {
53-
$color = 'is-danger';
54-
$message = $exception->getCode() === 429
55-
? 'Rate Limit Hit :( - Try later.'
56-
: 'Oops - something went wrong.';
57-
} catch (\Throwable $exception) {
58-
Log::error($exception->getMessage());
59-
$color = 'is-danger';
60-
$message = 'Oops - something went wrong.';
61-
}
62-
} else {
63-
$color = 'is-info';
64-
$message = 'Checking for updated stats.';
54+
Cache::put($cacheKey, true, now()->addMinutes($cooldownMinutes));
55+
$this->emitToRespectiveComponent();
56+
});
57+
} catch (RequestException $exception) {
58+
$color = 'is-danger';
59+
$message = $exception->getCode() === 429
60+
? 'Rate Limit Hit :( - Try later.'
61+
: 'Oops - something went wrong.';
62+
} catch (\Throwable $exception) {
63+
Log::error($exception->getMessage());
64+
$color = 'is-danger';
65+
$message = 'Oops - something went wrong.';
6566
}
6667
}
6768

0 commit comments

Comments
 (0)