CleanCommand   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 0
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 14 1
1
<?php
2
3
namespace PendoNL\LaravelScheduleLogger\Commands;
4
5
use Carbon\Carbon;
6
use Illuminate\Console\Command;
7
use PendoNL\LaravelScheduleLogger\Schedulelog;
8
9
class CleanCommand extends Command
10
{
11
    /**
12
     * The console command name.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'schedulelogger:clean {days=30}';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Clean up old records from the schedule log.';
24
25
    public function handle()
26
    {
27
        $maxAgeInDays = $this->argument('days');
28
29
        $this->comment("Cleaning schedule log, but keeping the records of the last {$maxAgeInDays} days...");
30
31
        $cutOffDate = Carbon::now()->subDays($maxAgeInDays)->format('Y-m-d H:i:s');
32
33
        $amountDeleted = Schedulelog::where('created_at', '<', $cutOffDate)->delete();
34
35
        $this->info("Deleted {$amountDeleted} record(s) from the schedule log.");
36
37
        $this->comment('All done!');
38
    }
39
}
40