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

CheckRetentionCommand::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 9
ccs 0
cts 6
cp 0
rs 10
cc 2
nc 2
nop 0
crap 6
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\Events\HistoryExpired;
0 ignored issues
show
Bug introduced by
The type VictorAvelar\Geld\Events\HistoryExpired was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use VictorAvelar\Geld\Models\CurrencyHistory;
11
12
class CheckRetentionCommand extends Command
13
{
14
    protected $signature = 'geld:retention';
15
16
    protected $description = 'Soft deletes records older than the retention period config value';
17
18
    /**
19
     * CheckRetentionCommand 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.history_mode')) {
32
            $edge = new DateTime('@'.strtotime('- '.config('geld.retention_period')));
33
34
            CurrencyHistory::where('created_at', '<', $edge)
35
                ->delete();
36
37
            Log::info("History records soft deleted successfully");
38
        }
39
    }
40
}
41