Skip to content

Commit

Permalink
Convert methods to non static
Browse files Browse the repository at this point in the history
  • Loading branch information
francoism90 authored Oct 31, 2024
1 parent ea1ab96 commit 403cb06
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/Views/Concerns/WithRateLimiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ trait WithRateLimiter

protected function rateLimit(): void
{
$maxAttempts = static::getMaxAttempts();
$maxAttempts = $this->getMaxAttempts();

if ($maxAttempts < 1) {
return;
}

$key = static::getRateLimitKey();
$key = $this->getRateLimitKey();

if (RateLimiter::tooManyAttempts($key, $maxAttempts)) {
throw new RateLimitedException(
Expand All @@ -28,41 +28,41 @@ protected function rateLimit(): void
);
}

static::incrementRateLimiter();
$this->incrementRateLimiter();
}

protected static function incrementRateLimiter(): void
protected function incrementRateLimiter(): void
{
RateLimiter::increment(
key: static::getRateLimitKey(),
decaySeconds: static::getDecaySeconds(),
amount: static::getRateLimitAmount(),
key: $this->getRateLimitKey(),
decaySeconds: $this->getDecaySeconds(),
amount: $this->getRateLimitAmount(),
);
}

protected static function clearRateLimiter(): void
protected function clearRateLimiter(): void
{
RateLimiter::clear(static::getRateLimitKey());
RateLimiter::clear($this->getRateLimitKey());
}

protected static function getRateLimitKey(): string
protected function getRateLimitKey(): string
{
return hash('crc32c', serialize([
return hash('xxh128', serialize([
get_called_class(), request()->ip(),
]));
}

protected static function getMaxAttempts(): int
protected function getMaxAttempts(): int
{
return static::$maxAttempts;
}

protected static function getDecaySeconds(): int
protected function getDecaySeconds(): int
{
return static::$decaySeconds;
}

protected static function getRateLimitAmount(): int
protected function getRateLimitAmount(): int
{
return 1;
}
Expand Down

0 comments on commit 403cb06

Please sign in to comment.