Skip to content

Commit

Permalink
working on formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Aug 26, 2017
1 parent dfa0209 commit 0a10f9a
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/Illuminate/Routing/Middleware/ThrottleRequestsWithRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,24 @@ public function handle($request, Closure $next, $maxAttempts = 60, $decayMinutes
}

/**
* Get the number of seconds until the next retry.
* Determine if the given key has been "accessed" too many times.
*
* @param string $key
* @return int
* @param int $maxAttempts
* @param int $decayMinutes
* @return mixed
*/
protected function getTimeUntilNextRetry($key)
protected function tooManyAttempts($key, $maxAttempts, $decayMinutes)
{
return $this->decaysAt - $this->currentTime();
$limiter = new DurationLimiter(
$this->redis, $key, $maxAttempts, $decayMinutes * 60
);

return tap(! $limiter->acquire(), function () use ($limiter) {
list($this->decaysAt, $this->remaining) = [
$limiter->decaysAt, $limiter->remaining,
];
});
}

/**
Expand All @@ -97,23 +107,13 @@ protected function calculateRemainingAttempts($key, $maxAttempts, $retryAfter =
}

/**
* Determine if the given key has been "accessed" too many times.
* Get the number of seconds until the lock is released.
*
* @param string $key
* @param int $maxAttempts
* @param int $decayMinutes
* @return mixed
* @return int
*/
protected function tooManyAttempts($key, $maxAttempts, $decayMinutes)
protected function getTimeUntilNextRetry($key)
{
$limiter = (new DurationLimiter($this->redis, $key, $maxAttempts, $decayMinutes * 60));

$attempt = $limiter->acquire();

$this->decaysAt = $limiter->decaysAt;

$this->remaining = $limiter->remaining;

return ! $attempt;
return $this->decaysAt - $this->currentTime();
}
}

0 comments on commit 0a10f9a

Please sign in to comment.