PdoMailJob   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 77
ccs 17
cts 17
cp 1
rs 10
wmc 7

6 Methods

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