PruneTokensStorageCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 31
ccs 7
cts 7
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 10 2
1
<?php
2
3
4
namespace JWTAuth\Console;
5
6
use Carbon\Carbon;
7
use Illuminate\Console\Command;
8
use JWTAuth\Eloquent\StoredJwtToken;
9
10
class PruneTokensStorageCommand extends Command
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'jwt:storage:prune {--days=30 : The number of days to retain StoredJwtToken data}';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Prune stale entries from the StoredJwtToken table';
25
26
    /**
27
     * Execute the console command.
28
     *
29
     * @return int
30
     */
31 3
    public function handle(): int
32
    {
33 3
        $deleted = StoredJwtToken::query()
34 3
            ->where('created_at', '<', Carbon::now()->subDays($this->option('days')))
35 3
            ->delete();
36 2
        if ($deleted) {
37 2
            $this->info('Stored tokens pruned.');
38
        }
39
40 2
        return 0;
41
    }
42
}
43