Completed
Pull Request — master (#447)
by Marcel
02:47 queued 01:22
created

CleanStatistics   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 12 2
1
<?php
2
3
namespace BeyondCode\LaravelWebSockets\Console\Commands;
4
5
use BeyondCode\LaravelWebSockets\Facades\StatisticsStore;
6
use Illuminate\Console\Command;
7
8
class CleanStatistics extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'websockets:clean
16
        {appId? : (optional) The app id that will be cleaned.}
17
        {--days= : Delete records older than this amount of days since now.}
18
    ';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string|null
24
     */
25
    protected $description = 'Clean up old statistics from the WebSocket statistics storage.';
26
27
    /**
28
     * Run the command.
29
     *
30
     * @return void
31
     */
32
    public function handle()
33
    {
34
        $this->comment('Cleaning WebSocket Statistics...');
35
36
        $days = $this->option('days') ?: config('statistics.delete_statistics_older_than_days');
37
38
        $amountDeleted = StatisticsStore::delete(
39
            now()->subDays($days), $this->argument('appId')
40
        );
41
42
        $this->info("Deleted {$amountDeleted} record(s) from the WebSocket statistics storage.");
43
    }
44
}
45