From e1b39c28adc05515251684fcccf9227ac9b0190b Mon Sep 17 00:00:00 2001 From: Isaac Souza Date: Thu, 16 Nov 2023 15:23:05 -0300 Subject: [PATCH] Drop extra methods --- src/Models/ApiKey.php | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/src/Models/ApiKey.php b/src/Models/ApiKey.php index 405dbb5..e700923 100644 --- a/src/Models/ApiKey.php +++ b/src/Models/ApiKey.php @@ -105,13 +105,12 @@ public function scopeOfKey(Builder $query, string $key): Builder if ($compatibilityMode) { return $query->where(function (Builder $query) use ($key) { - if ($this->isMissingId($key)) { + if (! str_contains($key, '|')) { return $query->where('key', $key) ->orWhere('key', hash('sha256', $key)); } - $id = $this->extractId($key); - $key = $this->extractKey($key); + [$id, $key] = explode('|', $key, 2); return $query ->where(function (Builder $query) use ($key, $id) { @@ -125,26 +124,13 @@ public function scopeOfKey(Builder $query, string $key): Builder }); } - if ($this->isMissingId($key)) { + if (! str_contains($key, '|')) { return $query->where('key', hash('sha256', $key)); } - return $query->where('id', $this->extractId($key)) - ->where('key', hash('sha256', $this->extractKey($key))); - } - - private function isMissingId(string $key): bool - { - return strpos($key, '|') === false; - } + [$id, $key] = explode('|', $key, 2); - private function extractId(string $key): string - { - return explode('|', $key, 2)[0]; - } - - private function extractKey(string $key): string - { - return explode('|', $key, 2)[1]; + return $query->where('id', $id) + ->where('key', hash('sha256', $key)); } }