CleanStatistics::handle()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 11
rs 10
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')
0 ignored issues
show
Bug introduced by
It seems like $days can also be of type string; however, parameter $value of Carbon\Carbon::subDays() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
            now()->subDays(/** @scrutinizer ignore-type */ $days), $this->argument('appId')
Loading history...
Bug introduced by
It seems like $this->argument('appId') can also be of type array; however, parameter $appId of BeyondCode\LaravelWebSoc...atisticsStore::delete() does only seem to accept integer|null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
            now()->subDays($days), /** @scrutinizer ignore-type */ $this->argument('appId')
Loading history...
40
        );
41
42
        $this->info("Deleted {$amountDeleted} record(s) from the WebSocket statistics storage.");
43
    }
44
}
45