Completed
Push — master ( 9eae13...e56856 )
by Antonio
04:26
created

PdoMailJob::setId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
namespace Da\Mailer\Queue\Backend\Pdo;
3
4
use Da\Mailer\Event\EventHandlerTrait;
5
use Da\Mailer\Model\MailJob;
6
7
class PdoMailJob extends MailJob
8
{
9
    use EventHandlerTrait;
10
11
    /**
12
     * State new.
13
     */
14
    const STATE_NEW = 'N';
15
    /**
16
     * State active or in process.
17
     */
18
    const STATE_ACTIVE = 'A';
19
    /**
20
     * State completed.
21
     */
22
    const STATE_COMPLETED = 'C';
23
    /**
24
     * @var string the date value to when to send the email when processing the queue from a daemon. The format is
25
     * `Y-m-d H:i:s`
26
     */
27
    private $timeToSend;
28
    /**
29
     * @var string
30
     */
31
    private $state = self::STATE_NEW;
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 6
    public function __construct(array $config = [])
37
    {
38 6
        parent::__construct($config);
39 6
    }
40
41
    /**
42
     * @return string
43
     */
44 4
    public function getTimeToSend()
45
    {
46 4
        return $this->timeToSend ?: date('Y-m-d H:i:s', time());
47
    }
48
49
    /**
50
     * @param string $date
51
     */
52 5
    public function setTimeToSend($date)
53
    {
54 5
        $this->timeToSend = $date;
55 5
    }
56
57
    /**
58
     * @return string
59
     */
60 3
    public function getState()
61
    {
62 3
        return $this->state;
63
    }
64
65
    /**
66
     * Marks the state as completed. After marking the instance as completed, we should call the
67
     * `PdoQueueStoreAdapter::ack()` method to update the database with new status.
68
     */
69 2
    public function markAsCompleted()
70
    {
71 2
        $this->state = self::STATE_COMPLETED;
72
73 2
        parent::markAsCompleted();
74 2
    }
75
76
    /**
77
     * Marks the state as new. If we update the status back to 'N'ew, we could send it back to queue by using the
78
     * `PdoQueueStoreAdapter::ack()` method. That means even including a new time to be processed in the future by
79
     * setting the `$timeToSend` in a future date.
80
     */
81 1
    public function markAsNew()
82
    {
83 1
        $this->state = self::STATE_NEW;
84 1
    }
85
}
86