Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahem-kamal committed Feb 5, 2024
2 parents 7e82a3e + 3ac28df commit 5383e48
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/Otp.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public function setValidateUniquenessAfterGeneration(bool $validateUniquenessAft

public function generate($otp = null): OtpCode
{
if (!$this->model) {
if (! $this->model) {
throw new \Exception('Model is required to generate otp');
}
$otp = $otp ?? $this->generatePassword();
if (!$this->validateOtpUniqueness($otp)) {
if (! $this->validateOtpUniqueness($otp)) {
return $this->generate();
}

Expand All @@ -58,7 +58,7 @@ public function generate($otp = null): OtpCode
'otp' => $otp,
'phone' => $this->getPhone(),
'service' => $this->service,
'expires_at' => now()->addMinutes(config('otp.services.' . $this->service . '.expires_in')),
'expires_at' => now()->addMinutes(config('otp.services.'.$this->service.'.expires_in')),
]);
}

Expand All @@ -76,7 +76,7 @@ public function setGeneratorOptions($length = 4, $numbers = true, $letters = fal

public function setService(string $service = 'default'): static
{
if (!config('otp.services.' . $service)) {
if (! config('otp.services.'.$service)) {
throw new \Exception('Service not found in the config file');
}
$this->service = $service;
Expand Down Expand Up @@ -117,17 +117,17 @@ public function setModel(HasOtp $model): static

private function validateOtpUniqueness(string $otp): bool
{
if (!$this->isValidateUniquenessAfterGeneration()) {
if (! $this->isValidateUniquenessAfterGeneration()) {
return true;
}

return !$this->model->otpCodes()->where('phone', $this->phone)
return ! $this->model->otpCodes()->where('phone', $this->phone)
->where('service', $this->service)->where('otp', $otp)->exists();
}

public function verifyOtp(string $otp): ServiceResponse
{
if (!$this->model) {
if (! $this->model) {
throw new \Exception('Model is required to verify otp');
}
$otpCode = $this->model->otpCodes()->where('otp', $otp)->where('phone', $this->phone)
Expand All @@ -147,7 +147,7 @@ public function verifyOtp(string $otp): ServiceResponse
/** @phpstan-ignore-next-line */
$otpCode->verified_at = now();
/** @phpstan-ignore-next-line */
if ($handlers = config('otp.services.' . $otpCode->service . '.handlers')) {
if ($handlers = config('otp.services.'.$otpCode->service.'.handlers')) {
foreach ($handlers as $handler) {
app($handler)->handle($otpCode);
}
Expand All @@ -161,7 +161,7 @@ public function verifyOtp(string $otp): ServiceResponse

private function setDefaults(): void
{
$generatorOptions = config('otp.services.' . $this->service . '.otp_generator_options');
$generatorOptions = config('otp.services.'.$this->service.'.otp_generator_options');

if ($generatorOptions) {
$this->setGeneratorOptions(
Expand All @@ -178,7 +178,7 @@ private function setDefaults(): void
symbols: config('otp.fallback_options.otp_generator_options.symbols'),
);
}
$this->setValidateUniquenessAfterGeneration(config('otp.services.' . $this->service . '.validate_uniqueness_after_generation') ?? config('otp.fallback_options.validate_uniqueness_after_generation'));
$this->setValidateUniquenessAfterGeneration(config('otp.services.'.$this->service.'.validate_uniqueness_after_generation') ?? config('otp.fallback_options.validate_uniqueness_after_generation'));
}

public function getGeneratorOptions(): array
Expand Down

0 comments on commit 5383e48

Please sign in to comment.