Passed
Push — master ( de070a...e0aded )
by Dan Michael O.
06:03
created

PurgeLogs   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 17 4
1
<?php
2
3
namespace App\Console\Commands;
4
5
class PurgeLogs extends Command
6
{
7
    /**
8
     * The name and signature of the console command.
9
     *
10
     * @var string
11
     */
12
    protected $signature = 'bibrex:purge-logs';
13
14
    /**
15
     * The console command description.
16
     *
17
     * @var string
18
     */
19
    protected $description = 'Purge old log entries.';
20
21
    /**
22
     * Execute the console command.
23
     *
24
     * @return mixed
25
     */
26
    public function handle()
27
    {
28
        $channels = config('logging.channels.stack.channels');
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        $channels = /** @scrutinizer ignore-call */ config('logging.channels.stack.channels');
Loading history...
29
        if (!in_array('postgres', $channels)) {
30
            return;
31
        }
32
33
        $days = (int) config('logging.channels.postgres.days');
34
        if ($days <= 0) {
35
            return;
36
        }
37
38
        $deleted = \DB::delete("DELETE FROM log WHERE time < now() - interval '$days day'");
0 ignored issues
show
Bug introduced by
The type DB 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...
39
        if ($deleted > 0) {
40
            $this->logInfo("$deleted loggmeldinger ble slettet");
41
        } else {
42
            $this->info("Ingen loggmeldinger ble slettet");
43
        }
44
    }
45
}
46