RecordsTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 52.94%

Importance

Changes 1
Bugs 1 Features 1
Metric Value
wmc 5
eloc 18
c 1
b 1
f 1
dl 0
loc 53
ccs 9
cts 17
cp 0.5294
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setSentDateField() 0 3 1
A getSentDateField() 0 3 1
A reduceEmailsByType() 0 8 2
A reduceOldEmailsData() 0 15 1
1
<?php
2
3
namespace Nip\MailModule\Models\EmailsTable\Traits\Cleanup;
4
5
use Nip\Config\Config;
6
use Nip\Database\Query\Update;
7
8
/**
9
 * Trait RecordsTrait
10
 * @package Nip\Mail\Models\Cleanup
11
 */
12
trait RecordsTrait
13
{
14
    protected static $sentDateField = 'date_sent';
15
16
    protected $daysToKeepData = 500;
17
18
    /**
19
     * @return \Nip\Database\Result
20
     */
21 1
    public function reduceOldEmailsData()
22
    {
23
        /** @var Update $query */
24 1
        $query = $this->newUpdateQuery();
0 ignored issues
show
Bug introduced by
It seems like newUpdateQuery() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

24
        /** @scrutinizer ignore-call */ 
25
        $query = $this->newUpdateQuery();
Loading history...
25 1
        $query->where(
26 1
            '`' . $this::getSentDateField() . '` <= DATE_SUB(CURRENT_DATE(), INTERVAL ' . $this->daysToKeepData . ' DAY)'
27
        );
28 1
        $query->data([
29 1
            'vars' => '',
30
            'body' => '',
31
            'compiled_subject' => '',
32
            'compiled_body' => '',
33
        ]);
34
35 1
        return $query->execute();
36
    }
37
38
    /**
39
     * @return string
40
     */
41 2
    public static function getSentDateField(): string
42
    {
43 2
        return self::$sentDateField;
44
    }
45
46
    /**
47
     * @param string $sentDateField
48
     */
49
    public static function setSentDateField(string $sentDateField)
50
    {
51
        self::$sentDateField = $sentDateField;
52
    }
53
54
    /**
55
     * @return float[]|int[]
56
     */
57
    public static function reduceEmailsByType(): array
58
    {
59
        $config = config('mail.cleanup.ttl');
60
61
        if ($config instanceof Config) {
62
            return $config->toArray();
63
        }
64
        return ['*' => 365 * 2];
65
    }
66
}
67