Passed
Pull Request — master (#20)
by Hilmi Erdem
13:59 queued 07:56
created

DatabaseTokenRepository   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 15
rs 10
c 1
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A persist() 0 7 1
1
<?php
2
/*
3
 * Copyright (c) 2021. Hilmi Erdem Keren
4
 * license MIT
5
 */
6
7
namespace Erdemkeren\Otp\Repositories;
8
9
use Erdemkeren\Otp\Contracts\TokenRepositoryContract;
10
use Erdemkeren\Otp\OtpToken;
11
use Illuminate\Support\Facades\DB;
12
13
/**
14
 * Class DatabaseTokenRepository.
15
 */
16
class DatabaseTokenRepository implements TokenRepositoryContract
17
{
18
    /**
19
     * Save the given token in the storage.
20
     *
21
     * @param  OtpToken  $token
22
     * @return bool
23
     */
24
    public function persist(OtpToken $token): bool
25
    {
26
        return DB::transaction(
27
            fn (): bool => DB::table('otp_tokens')->updateOrInsert([
28
                'authenticable_id' => $token->authenticableId(),
29
                'cipher_text'      => $token->cipherText(),
30
            ], $token->withoutPlainText()->toArray())
31
        );
32
    }
33
}
34