Airship\Engine\Security\AirBrake::getDelay PHP Method

getDelay() public method

Get the throttling delay (in milliseconds)
public getDelay ( string $username, string $ip, string $action = self::ACTION_LOGIN ) : integer
$username string
$ip string
$action string
return integer
    public function getDelay(string $username, string $ip, string $action = self::ACTION_LOGIN) : int
    {
        $attempts = (int) $this->db->cell('SELECT
                 count(*)
             FROM
                 airship_failed_logins
             WHERE
                 action = ?
                 AND (
                        username = ?
                     OR subnet = ?
                 )
                 AND occurred > ?
             ', $action, $username, $this->getSubnet($ip), (new \DateTime())->sub($this->getCutoff((int) ($this->config['expire'] ?? 43200)))->format(\AIRSHIP_DATE_FORMAT));
        if ($attempts === 0) {
            return 0;
        }
        $max = (int) ($this->config['max-delay'] ?? 30);
        $value = (double) ($this->config['first-delay'] ?? 0.25);
        if ($attempts > 8 * PHP_INT_SIZE - 1) {
            // Don't ever overflow. Just assume the max time:s
            $value = $max;
        } else {
            $value *= 2 ** $attempts;
            if ($value > $max) {
                $value = $max;
            }
        }
        return (int) \ceil($value * 1000);
    }