Passed
Push — master ( 50509a...5c86f2 )
by Hirofumi
03:29
created

Notification::sentAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shippinno\Notification\Domain\Model;
5
6
use DateTimeImmutable;
7
use LogicException;
8
9
class Notification
10
{
11
    /**
12
     * @var null|NotificationId
13
     */
14
    protected $notificationId;
15
16
    /**
17
     * @var Destination
18
     */
19
    protected $destination;
20
21
    /**
22
     * @var Subject
23
     */
24
    protected $subject;
25
26
    /**
27
     * @var Body
28
     */
29
    protected $body;
30
31
    /**
32
     * @var null|DeduplicationKey
33
     */
34
    protected $deduplicationKey;
35
36
    /**
37
     * @var null|string
38
     */
39
    protected $templateName;
40
41
    /**
42
     * @var array|null
43
     */
44
    protected $templateVariables;
45
46
    /**
47
     * @var DateTimeImmutable
48
     */
49
    protected $createdAt;
50
51
    /**
52
     * @var null|DateTimeImmutable
53
     */
54
    protected $sentAt;
55
56
    /**
57
     * @param Destination $destination
58
     * @param Subject $subject
59
     * @param Body $body
60
     * @param DeduplicationKey|null $deduplicationKey
61
     * @param string|null $templateName
62
     * @param array|null $templateVariables
63
     */
64 4
    public function __construct(
65
        Destination $destination,
66
        Subject $subject,
67
        Body $body,
68
        DeduplicationKey $deduplicationKey = null,
69
        string $templateName = null,
70
        array $templateVariables = null
71
    ) {
72 4
        $this->destination = $destination;
73 4
        $this->subject = $subject;
74 4
        $this->body = $body;
75 4
        $this->deduplicationKey = $deduplicationKey;
76 4
        $this->templateName = $templateName;
77 4
        $this->templateVariables = $templateVariables;
78 4
        $this->createdAt = new DateTimeImmutable;
79 4
        $this->sentAt = null;
80 4
    }
81
82
    /**
83
     * @return null|NotificationId
84
     */
85 1
    public function notificationId(): ?NotificationId
86
    {
87 1
        return $this->notificationId;
88
    }
89
90
    /**
91
     * @return Destination
92
     */
93
    public function destination(): Destination
94
    {
95
        return $this->destination;
96
    }
97
98
    /**
99
     * @return Subject
100
     */
101 1
    public function subject(): Subject
102
    {
103 1
        return $this->subject;
104
    }
105
106
    /**
107
     * @return Body
108
     */
109 1
    public function body(): Body
110
    {
111 1
        return $this->body;
112
    }
113
114
    /**
115
     * @return null|DeduplicationKey
116
     */
117 3
    public function deduplicationKey(): ?DeduplicationKey
118
    {
119 3
        return $this->deduplicationKey;
120
    }
121
122
    /**
123
     * @return DateTimeImmutable
124
     */
125
    public function createdAt(): DateTimeImmutable
126
    {
127
        return $this->createdAt;
128
    }
129
130
    /**
131
     * @return DateTimeImmutable|null
132
     */
133 1
    public function sentAt(): ?DateTimeImmutable
134
    {
135 1
        return $this->sentAt;
136
    }
137
138
    /**
139
     * @return bool
140
     */
141 1
    public function isSent(): bool
142
    {
143 1
        return !is_null($this->sentAt());
144
    }
145
146
    /**
147
     * @return void
148
     */
149 1
    public function markSent(): void
150
    {
151 1
        if ($this->isSent()) {
152
            throw new LogicException(sprintf('Notification is already sent: %s', $this->notificationId->id()));
153
        }
154 1
        $this->sentAt = new DateTimeImmutable;
155 1
    }
156
}
157
158
159