Cartalyst\Sentinel\Throttling\IlluminateThrottleRepository::delay PHP Method

delay() protected method

Returns a delay for the given type.
protected delay ( string $type, mixed $argument = null ) : integer
$type string
$argument mixed
return integer
    protected function delay($type, $argument = null)
    {
        // Based on the given type, we will generate method and property names
        $method = 'get' . studly_case($type) . 'Throttles';
        $thresholds = $type . 'Thresholds';
        $throttles = $this->{$method}($argument);
        if (!$throttles->count()) {
            return 0;
        }
        if (is_array($this->{$thresholds})) {
            // Great, now we compare our delay against the most recent attempt
            $last = $throttles->last();
            foreach (array_reverse($this->{$thresholds}, true) as $attempts => $delay) {
                if ($throttles->count() <= $attempts) {
                    continue;
                }
                if ($last->created_at->diffInSeconds() < $delay) {
                    return $this->secondsToFree($last, $delay);
                }
            }
        } elseif ($throttles->count() > $this->{$thresholds}) {
            $interval = $type . 'Interval';
            $first = $throttles->first();
            return $this->secondsToFree($first, $this->{$interval});
        }
        return 0;
    }