Total Complexity | 5 |
Total Lines | 61 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
10 | class DatabaseOtpsRepository implements ClearableRepository, PrunableRepository |
||
11 | { |
||
12 | |||
13 | /** |
||
14 | * The database connection name that should be used. |
||
15 | * |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $connection; |
||
19 | |||
20 | /** |
||
21 | * Create a new database repository. |
||
22 | * |
||
23 | * @param string $connection |
||
24 | * @return void |
||
25 | */ |
||
26 | public function __construct(string $connection) |
||
27 | { |
||
28 | $this->connection = $connection; |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Prune all of the entries older than the given date. |
||
33 | * |
||
34 | * @param \DateTimeInterface $before |
||
35 | * @return int |
||
36 | */ |
||
37 | public function prune(DateTimeInterface $before) |
||
38 | { |
||
39 | $query = $this->table('otps')->where('expired', true)->orWhere('created_at', '<', $before); |
||
40 | |||
41 | $totalDeleted = 0; |
||
42 | |||
43 | do { |
||
44 | $deleted = $query->take(100)->delete(); |
||
45 | |||
46 | $totalDeleted += $deleted; |
||
47 | } while ($deleted !== 0); |
||
48 | |||
49 | return $totalDeleted; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Clear all the entries. |
||
54 | * |
||
55 | * @return void |
||
56 | */ |
||
57 | public function clear() |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Get a query builder instance for the given table. |
||
64 | * |
||
65 | * @param string $table |
||
66 | * @return \Illuminate\Database\Query\Builder |
||
67 | */ |
||
68 | protected function table($table) |
||
73 |