RecordsTrait::getSentDateField()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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