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

DataIncineratorCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 33.33%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 9 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 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