CheckRetentionCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
c 1
b 0
f 0
dl 0
loc 26
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 9 2
1
<?php
2
3
namespace VictorAvelar\Geld\Commands;
4
5
use DateTime;
6
use Exception;
7
use Illuminate\Console\Command;
8
use Illuminate\Support\Facades\Log;
9
use VictorAvelar\Geld\Models\CurrencyHistory;
10
11
class CheckRetentionCommand extends Command
12
{
13
    protected $signature = 'geld:retention';
14
15
    protected $description = 'Soft deletes records older than the retention period config value';
16
17
    /**
18
     * CheckRetentionCommand constructor.
19
     */
20 15
    public function __construct()
21
    {
22 15
        parent::__construct();
23 15
    }
24
25
    /**
26
     * @throws Exception
27
     */
28 6
    public function handle()
29
    {
30 6
        if (config('geld.history_mode')) {
31 6
            $retention = '@'.strtotime('-'.config('geld.retention'));
32 6
            $edge = new DateTime($retention);
33 6
            CurrencyHistory::where('created_at', '<', $edge)
34 6
                ->delete();
35
36 6
            Log::info("History records soft deleted successfully");
37
        }
38 6
    }
39
}
40