From 1f644e7bdb92feaa3e7b3b2923e7ea30212227ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Ca=C5=82ka?= Date: Sat, 30 Dec 2023 14:11:59 +0100 Subject: [PATCH] refactor: remove duplicated code --- src/Command/LSCacheClearCommand.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Command/LSCacheClearCommand.php b/src/Command/LSCacheClearCommand.php index e291ec9..ab1436f 100644 --- a/src/Command/LSCacheClearCommand.php +++ b/src/Command/LSCacheClearCommand.php @@ -41,7 +41,8 @@ protected function fire(): int //Create a temporary API key to authorize a request $apiKey = new ApiKey(); $key = $apiKey::generate()->key; - //The key is saved temporarily in the settings. The native Flarum API key is not used because it requires a user ID and in the case of the command the user is not logged in. + //The key is saved temporarily in the settings. + //The native Flarum API key is not used because it requires a user ID but in the case of the command, the user is not logged in. $this->settings->set('acpl-lscache.purgeKey', $key); $options = [ @@ -59,20 +60,15 @@ protected function fire(): int //GET does not require the Flarum API key $client->request('GET', $this->url->to('api')->route('lscache.purge'), $options); } catch (GuzzleException $exception) { - $this->deleteKey(); $this->error('Something went wrong while sending the request.'); return 1; + } finally { + $this->settings->delete('acpl-lscache.purgeKey'); } - $this->deleteKey(); $this->info('Notified LiteSpeed Web Server to purge'.(empty($paths) ? ' all' : '').' LSCache entries'); return 0; } - - private function deleteKey(): void - { - $this->settings->delete('acpl-lscache.purgeKey'); - } }