Completed
Push — master ( 0666f9...1b5e97 )
by Victor Hugo
08:08
created

DataIncineratorCommand::__construct()   A

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 4
    public function __construct()
22
    {
23 4
        parent::__construct();
24 4
    }
25
26
    /**
27
     * @throws Exception
28
     */
29
    public function handle()
30
    {
31
        if (config('geld.incinerator')) {
32
            $edge = new DateTime('@'. strtotime('- '.config('geld.incinerate_after')));
33
34
            CurrencyHistory::where('created_at', '<', $edge)
35
                ->forceDelete();
36
37
            Log::info("Data incinerated successfully");
38
        }
39
    }
40
}
41