Skip to content

Commit

Permalink
Drop extra methods
Browse files Browse the repository at this point in the history
  • Loading branch information
isaac-souza committed Nov 16, 2023
1 parent 22a752d commit e1b39c2
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions src/Models/ApiKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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));
}
}

0 comments on commit e1b39c2

Please sign in to comment.