ClearCommand::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 10
rs 10
1
<?php
2
3
namespace Yadahan\AuthenticationLog\Console;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Carbon;
7
use Yadahan\AuthenticationLog\AuthenticationLog;
8
9
class ClearCommand extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'authentication-log:clear';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Clear old records from the authentication log';
24
25
    /**
26
     * Execute the console command.
27
     *
28
     * @return void
29
     */
30
    public function handle()
31
    {
32
        $this->comment('Clearing authentication log...');
33
34
        $days = config('authentication-log.older');
35
        $from = Carbon::now()->subDays($days)->format('Y-m-d H:i:s');
36
37
        AuthenticationLog::where('login_at', '<', $from)->delete();
38
39
        $this->info('Authentication log cleared successfully.');
40
    }
41
}
42