PruneTemporalKeysCommand   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 15
rs 10
c 0
b 0
f 0
ccs 8
cts 8
cp 1
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 9 1
1
<?php
2
3
namespace TemporalKey\Console\Commands;
4
5
use Carbon\Carbon;
6
use Illuminate\Console\Command;
7
use Illuminate\Database\Eloquent\Builder;
8
9
class PruneTemporalKeysCommand extends Command
10
{
11
    protected $signature = 'temporal-key:prune';
12
13
    protected $description = 'Remove expired temporal keys';
14
15 3
    public function handle()
16
    {
17 3
        \TemporalKey\TemporalKey::$storeModel::query()
18 3
            ->where('valid_until', '<=', Carbon::now())
19 3
            ->orWhere(function (Builder $q) {
20 3
                $q->where('usage_max', '>', 0)
21 3
                  ->whereRaw('`usage_max` <= `usage_counter`');
22 3
            })
23 3
            ->delete();
24
    }
25
}
26