Completed
Push — master ( 90fbaf...4a58e4 )
by Victor Hugo
23s
created

DataIncineratorCommand::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 8
ccs 7
cts 7
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
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