Completed
Push — master ( 5bbcf4...56ea65 )
by Gabriel
02:56
created

Email::setHtmlBody()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

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 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Omnimail;
4
5
class Email implements EmailInterface
6
{
7
    /**
8
     * @var array
9
     */
10
    protected $to = [];
11
12
    /**
13
     * @var array
14
     */
15
    protected $cc = [];
16
17
    /**
18
     * @var array
19
     */
20
    protected $bcc = [];
21
22
    /**
23
     * @var array
24
     */
25
    protected $replyTo = [];
26
27
    /**
28
     * @var array
29
     */
30
    protected $attachments = [];
31
32
    /**
33
     * @var array
34
     */
35
    protected $from;
36
37
    /**
38
     * @var string
39
     */
40
    protected $subject;
41
42
    /**
43
     * @var string
44
     */
45
    protected $textBody;
46
47
    /**
48
     * @var string
49
     */
50
    protected $htmlBody;
51
52
    /**
53
     * @return string
54
     */
55 9
    public function getTextBody()
56
    {
57 9
        return $this->textBody;
58
    }
59
60
    /**
61
     * @param string $textBody
62
     * @return $this
63
     */
64 9
    public function setTextBody($textBody)
65
    {
66 9
        $this->textBody = $textBody;
67 9
        return $this;
68
    }
69
70
    /**
71
     * @return string
72
     */
73 9
    public function getHtmlBody()
74
    {
75 9
        return $this->htmlBody;
76
    }
77
78
    /**
79
     * @param string $htmlBody
80
     * @return $this
81
     */
82 1
    public function setHtmlBody($htmlBody)
83
    {
84 1
        $this->htmlBody = $htmlBody;
85 1
        return $this;
86
    }
87
88
    /**
89
     * @return string
90
     */
91 9
    public function getFrom()
92
    {
93 9
        return $this->from;
94
    }
95
96
    /**
97
     * @param string $email
98
     * @param string|null $name
99
     * @return $this
100
     */
101 9
    public function setFrom($email, $name = null)
102
    {
103 9
        $this->from = ['email' => $email, 'name' => $name];
104 9
        return $this;
105
    }
106
107
    /**
108
     * @return string
109
     */
110 8
    public function getSubject()
111
    {
112 8
        return $this->subject;
113
    }
114
115
    /**
116
     * @param string $subject
117
     * @return $this
118
     */
119 9
    public function setSubject($subject)
120
    {
121 9
        $this->subject = $subject;
122 9
        return $this;
123
    }
124
125
    /**
126
     * @return array
127
     */
128 9
    public function getTos()
129
    {
130 9
        return $this->to;
131
    }
132
133
    /**
134
     * @param string $email
135
     * @param string|null $name
136
     * @return $this
137
     */
138 9
    public function addTo($email, $name = null)
139
    {
140 9
        $this->to[] = [
141 9
            'email' => $email,
142
            'name' => $name
143 9
        ];
144 9
        return $this;
145
    }
146
147
    /**
148
     * @return array
149
     */
150 9
    public function getCcs()
151
    {
152 9
        return $this->cc;
153
    }
154
155
    /**
156
     * @param string $email
157
     * @param string|null $name
158
     * @return $this
159
     */
160 1
    public function addCc($email, $name = null)
161
    {
162 1
        $this->cc[] = [
163 1
            'email' => $email,
164
            'name' => $name
165 1
        ];
166 1
        return $this;
167
    }
168
169
    /**
170
     * @return array
171
     */
172 9
    public function getBccs()
173
    {
174 9
        return $this->bcc;
175
    }
176
177
    /**
178
     * @param string $email
179
     * @param string|null $name
180
     * @return $this
181
     */
182 1
    public function addBcc($email, $name = null)
183
    {
184 1
        $this->bcc[] = [
185 1
            'email' => $email,
186
            'name' => $name
187 1
        ];
188 1
        return $this;
189
    }
190
191
    /**
192
     * @return array
193
     */
194 9
    public function getReplyTos()
195
    {
196 9
        return $this->replyTo;
197
    }
198
199
    /**
200
     * @return array
201
     */
202
    public function getReplyTo()
203
    {
204
        return count($this->replyTo) > 0 ? $this->replyTo[0] : [];
205
    }
206
207
    /**
208
     * @param string $email
209
     * @param string|null $name
210
     * @return $this
211
     */
212 1
    public function addReplyTo($email, $name = null)
213
    {
214 1
        $this->replyTo[] = [
215 1
            'email' => $email,
216
            'name' => $name
217 1
        ];
218 1
        return $this;
219
    }
220
221
    /**
222
     * @param string $email
223
     * @param string|null $name
224
     * @return $this
225
     */
226
    public function setReplyTo($email, $name = null)
227
    {
228
        $this->replyTo = [[
229
            'email' => $email,
230
            'name' => $name
231
        ]];
232
        return $this;
233
    }
234
235
    /**
236
     * @return array
237
     */
238 9
    public function getAttachments()
239
    {
240 9
        return $this->attachments;
241
    }
242
243
    /**
244
     * @param AttachmentInterface $attachment
245
     * @return $this
246
     */
247
    public function addAttachment(AttachmentInterface $attachment)
248
    {
249
        $this->attachments[] = $attachment;
250
        return $this;
251
    }
252
253
    /**
254
     * @return array
255
     */
256 1
    public function toArray()
257
    {
258 1
        $attachments = $this->getAttachments();
259 1
        if (count($attachments)) {
260
            /**
261
             * @var int $key
262
             * @var AttachmentInterface $attachment
263
             */
264
            foreach ($attachments as $key => $attachment) {
265
                $attachments[$key] = $attachment->toArray();
266
            }
267
        }
268
269
        return [
270 1
            'textBody' => $this->getTextBody(),
271 1
            'htmlBody' => $this->getHtmlBody(),
272 1
            'from' => $this->getFrom(),
273 1
            'subject' => $this->getSubject(),
274 1
            'attachments' => $attachments,
275 1
            'tos' => $this->getTos(),
276 1
            'replyTos' => $this->getReplyTos(),
277 1
            'ccs' => $this->getCcs(),
278 1
            'bccs' => $this->getBccs()
279 1
        ];
280
    }
281
}
282