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)); } }