Skip to content

Commit

Permalink
docblock
Browse files Browse the repository at this point in the history
  • Loading branch information
jenky committed Mar 4, 2024
1 parent 439f823 commit 41eaabf
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Limit.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,37 @@ public static function allow(int $maxAttempts, int $expiresMinutes = 60): self
return new self($maxAttempts, $expiresMinutes * 60);
}

/**
* Get the limit key for caching.
*/
public function key(): string
{
$prefix = 'fansipan_rate_limit';

return $prefix.'_'.$this->name;
}

/**
* Get the limit max request attempts.
*/
public function maxAttempts(bool $includeThreshold = true): int
{
return $includeThreshold
? (int) \round($this->maxAttempts * $this->threshold, \PHP_ROUND_HALF_DOWN)
: $this->maxAttempts;
}

/**
* Get the expiration time in millisecond.
*/
public function expiresAfter(): int
{
return $this->expiresAfter;
}

/**
* Set a custom name for the limit.
*/
public function withName(string $name): self
{
$clone = clone $this;
Expand Down

0 comments on commit 41eaabf

Please sign in to comment.