Skip to content

Commit

Permalink
Fix type cast for manager rate-limits
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeygeno committed Aug 25, 2023
1 parent c8d2f3c commit 49aa3ae
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ public function initiate(string $phone): self

$rateLimitInitiate = $this->config['rate_limits']['initiate'];
if ($this->storage->sessionCounter($phone) >= (int)$rateLimitInitiate['count']) {
throw new RateLimit($rateLimitInitiate['message']($phone, $rateLimitInitiate['period_secs'], $rateLimitInitiate['count']), RateLimit::CODE_INITIATE);
throw new RateLimit($rateLimitInitiate['message']($phone, (int)$rateLimitInitiate['period_secs'], (int)$rateLimitInitiate['count']), RateLimit::CODE_INITIATE);
}
// Don't do anything in storage if sender::invoke throws an exception
$this->sender->invoke($phone, $message);
$this->storage->sessionUp($phone, $this->otp, $this->config['rate_limits']['complete']['period_secs'], $rateLimitInitiate['period_secs']);
$this->storage->sessionUp($phone, $this->otp, (int)$this->config['rate_limits']['complete']['period_secs'], (int)$rateLimitInitiate['period_secs']);
return $this;
}

Expand All @@ -146,14 +146,14 @@ public function complete(string $phone, int $otp): self
$rateLimit = $this->config['rate_limits']['complete'];

if ($this->storage->otpCheckCounter($phone) >= (int)$rateLimit['count']) {
throw new RateLimit($rateLimit['message']($phone, $rateLimit['period_secs'], $rateLimit['count']), RateLimit::CODE_COMPLETE);
throw new RateLimit($rateLimit['message']($phone, (int)$rateLimit['period_secs'], (int)$rateLimit['count']), RateLimit::CODE_COMPLETE);
}

$storedOtp = $this->storage->otp($phone);

// Expired otp!
if ($storedOtp === 0) {
throw new Otp($this->config['otp']['message_expired']($rateLimit['period_secs'], $otp), Otp::CODE_EXPIRED);
throw new Otp($this->config['otp']['message_expired']((int)$rateLimit['period_secs'], $otp), Otp::CODE_EXPIRED);
}
// Incorrect otp!
if ($storedOtp !== $otp) {
Expand Down

0 comments on commit 49aa3ae

Please sign in to comment.