MailgunMessageSummary::increaseOpenCount()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
c 1
b 1
f 0
1
<?php
2
3
namespace Azine\MailgunWebhooksBundle\Entity;
4
5
/**
6
 * MailgunMessageSummary.
7
 */
8
class MailgunMessageSummary
9
{
10
    /**
11
     * @var string
12
     */
13
    private $id;
14
15
    /**
16
     * @var string
17
     */
18
    private $fromAddress;
19
20
    /**
21
     * @var string
22
     */
23
    private $toAddress;
24
25
    /**
26
     * @var \DateTime
27
     */
28
    private $firstOpened;
29
30
    /**
31
     * @var \DateTime
32
     */
33
    private $lastOpened;
34
35
    /**
36
     * @var int
37
     */
38
    private $openCount;
39
40
    /**
41
     * @var \DateTime
42
     */
43
    private $sendDate;
44
45
    /**
46
     * @var string
47
     */
48
    private $deliveryStatus;
49
50
    /**
51
     * @var string
52
     */
53
    private $senderIp;
54
55
    /**
56
     * @var string
57
     */
58
    private $subject;
59
60
    /**
61
     * @var \Doctrine\Common\Collections\Collection
62
     */
63
    private $events;
64
65
    /**
66
     * Constructor.
67
     */
68
    public function __construct($id, \DateTime $sendDate, $fromAddress, $toAddress, $subject, $senderIp)
69
    {
70
        $this->events = new \Doctrine\Common\Collections\ArrayCollection();
71
        $this->id = $id;
72
        $this->sendDate = $sendDate;
73
        $this->fromAddress = $fromAddress;
74
        $this->toAddress = $toAddress;
75
        $this->subject = $subject;
76
        $this->senderIp = $senderIp;
77
        $this->openCount = 0;
78
    }
79
80
    /**
81
     * Append the latest event to the delivery status.
82
     *
83
     * @param $eventType
84
     */
85
    public function updateDeliveryStatus($eventType)
86
    {
87
        if (false === stripos($this->deliveryStatus, $eventType)) {
88
            $this->deliveryStatus = $this->deliveryStatus."$eventType, ";
89
        }
90
    }
91
92
    /**
93
     * Get id.
94
     *
95
     * @return string
96
     */
97
    public function getId()
98
    {
99
        return $this->id;
100
    }
101
102
    /**
103
     * Get fromAddress.
104
     *
105
     * @return string
106
     */
107
    public function getFromAddress()
108
    {
109
        return $this->fromAddress;
110
    }
111
112
    /**
113
     * Get toAddress.
114
     *
115
     * @return string
116
     */
117
    public function getToAddress()
118
    {
119
        return $this->toAddress;
120
    }
121
122
    /**
123
     * Set firstOpened.
124
     *
125
     * @param \DateTime $firstOpened
126
     *
127
     * @return MailgunMessageSummary
128
     */
129
    public function setFirstOpened($firstOpened)
130
    {
131
        $this->firstOpened = $firstOpened;
132
133
        return $this;
134
    }
135
136
    /**
137
     * Get firstOpened.
138
     *
139
     * @return \DateTime
140
     */
141
    public function getFirstOpened()
142
    {
143
        return $this->firstOpened;
144
    }
145
146
    /**
147
     * Set lastOpened.
148
     *
149
     * @param \DateTime $lastOpened
150
     *
151
     * @return MailgunMessageSummary
152
     */
153
    public function setLastOpened($lastOpened)
154
    {
155
        $this->lastOpened = $lastOpened;
156
157
        return $this;
158
    }
159
160
    /**
161
     * Get lastOpened.
162
     *
163
     * @return \DateTime
164
     */
165
    public function getLastOpened()
166
    {
167
        return $this->lastOpened;
168
    }
169
170
    /**
171
     * Increase openCount by 1.
172
     *
173
     * @return MailgunMessageSummary
174
     */
175
    public function increaseOpenCount()
176
    {
177
        ++$this->openCount;
178
179
        return $this;
180
    }
181
182
    /**
183
     * Get openCount.
184
     *
185
     * @return int
186
     */
187
    public function getOpenCount()
188
    {
189
        return $this->openCount;
190
    }
191
192
    /**
193
     * Get sendDate.
194
     *
195
     * @return \DateTime
196
     */
197
    public function getSendDate()
198
    {
199
        return $this->sendDate;
200
    }
201
202
    /**
203
     * Get deliveryStatus.
204
     *
205
     * @return string
206
     */
207
    public function getDeliveryStatus()
208
    {
209
        return trim($this->deliveryStatus, ', ');
210
    }
211
212
    /**
213
     * Get senderIp.
214
     *
215
     * @return string
216
     */
217
    public function getSenderIp()
218
    {
219
        return $this->senderIp;
220
    }
221
222
    /**
223
     * Set senderIp.
224
     *
225
     * @return MailgunMessageSummary
226
     */
227
    public function setSenderIp($ip)
228
    {
229
        $this->senderIp = $ip;
230
231
        return $this;
232
    }
233
234
    /**
235
     * Get events.
236
     *
237
     * @return \Doctrine\Common\Collections\Collection
238
     */
239
    public function getEvents()
240
    {
241
        return $this->events;
242
    }
243
244
    /**
245
     * Get subject.
246
     *
247
     * @return string
248
     */
249
    public function getSubject()
250
    {
251
        return $this->subject;
252
    }
253
254
    /**
255
     * Set subject.
256
     *
257
     * @return MailgunMessageSummary
258
     */
259
    public function setSubject($subject)
260
    {
261
        $this->subject = $subject;
262
263
        return $this;
264
    }
265
266
    /**
267
     * Set fromAddress.
268
     *
269
     * @return MailgunMessageSummary
270
     */
271
    public function setFromAddress($fromAddress)
272
    {
273
        $this->fromAddress = $fromAddress;
274
275
        return $this;
276
    }
277
278
    /**
279
     * Set toAddress.
280
     *
281
     * @return MailgunMessageSummary
282
     */
283
    public function appendToToAddress($toAddress)
284
    {
285
        if (false === stripos($this->toAddress, $toAddress)) {
286
            $this->toAddress = trim($this->toAddress.', '.$toAddress, ', ');
287
        }
288
289
        return $this;
290
    }
291
}
292