PruneTokensStorageCommand::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 10
ccs 7
cts 7
cp 1
crap 2
rs 10
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