DataIncineratorCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
4
namespace VictorAvelar\Geld\Commands;
5
6
use DateTime;
7
use Exception;
8
use Illuminate\Console\Command;
9
use Illuminate\Support\Facades\Log;
10
use VictorAvelar\Geld\Models\CurrencyHistory;
11
12
class DataIncineratorCommand extends Command
13
{
14
    protected $signature = 'geld:incinerate';
15
16
    protected $description = 'Removes records older than the specified incineration threshold';
17
18
    /**
19
     * DataIncineratorCommand constructor.
20
     */
21 15
    public function __construct()
22
    {
23 15
        parent::__construct();
24 15
    }
25
26
    /**
27
     * @throws Exception
28
     */
29 3
    public function handle()
30
    {
31 3
        if (config('geld.incinerate')) {
32 3
            $incinerate = '@'.strtotime('-'.config('geld.incinerate_after'));
33 3
            $edge = new DateTime($incinerate);
34 3
            CurrencyHistory::where('created_at', '<', $edge)
35 3
                ->forceDelete();
36 3
            Log::info("Data incinerated successfully");
37
        }
38 3
    }
39
}
40