Passed
Push — master ( d57c11...8c6e4f )
by Joao
03:16 queued 36s
created

Envelope::setTo()   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 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
namespace ByJG\Mail;
4
5
class Envelope
6
{
7
    protected $from = "";
8
    protected $to = [];
9
    protected $subject = "";
10
    protected $replyTo = "";
11
    protected $cc = [];
12
    protected $bcc = [];
13
    protected $body = "";
14
    protected $isHtml = false;
15
    protected $attachment = [];
16
17
    /**
18
     *
19
     * @param string $from
20
     * @param string $to
21
     * @param string $subject
22
     * @param string $body
23
     * @param bool $isHtml
24
     */
25 19
    public function __construct($from = "", $to = "", $subject = "", $body = "", $isHtml = true)
26
    {
27 19
        $this->from = Util::getFullEmail($from);
28 19
        $this->subject = $subject;
29 19
        $this->isHtml = $isHtml;
30 19
        $this->body = $body;
31
32 19
        if (!empty($to)) {
33 12
            $this->addTo($to);
34 12
        }
35 19
    }
36
37
    /**
38
     * @param string $contentName
39
     * @param string $filePath
40
     * @param string $contentType
41
     */
42 4
    public function addAttachment($contentName, $filePath, $contentType)
43
    {
44 4
        $this->attachment[$contentName] = [
45 4
            'content' => $filePath,
46 4
            'content-type' => $contentType,
47
            'disposition' => 'attachment'
48 4
        ];
49 4
    }
50
51
    /**
52
     * @param string $contentName
53
     * @param string $filePath
54
     * @param string $contentType
55
     */
56 3
    public function addEmbedImage($contentName, $filePath, $contentType)
57
    {
58 3
        $this->attachment[$contentName] = [
59 3
            'content' => $filePath,
60 3
            'content-type' => $contentType,
61
            'disposition' => 'inline'
62 3
        ];
63 3
    }
64
65 13
    public function getFrom()
66
    {
67 13
        return $this->from;
68
    }
69
70 1
    public function setFrom($email, $name = null)
71
    {
72 1
        $this->from = Util::getFullEmail($email, $name);
73 1
    }
74
75 13
    public function getTo()
76
    {
77 13
        return $this->to;
78
    }
79
80 1
    public function setTo($email, $name = "")
81
    {
82 1
        $this->to = [Util::getFullEmail($email, $name)];
83 1
    }
84
85 13
    public function addTo($email, $name = "")
86
    {
87 13
        $this->to[] = Util::getFullEmail($email, $name);
88 13
    }
89
90 13
    public function getSubject()
91
    {
92 13
        return $this->subject;
93
    }
94
95 1
    public function setSubject($value)
96
    {
97 1
        $this->subject = $value;
98 1
    }
99
100 12
    public function getReplyTo()
101
    {
102 12
        return $this->replyTo == "" ? $this->getFrom() : $this->replyTo;
103
    }
104
105
    public function setReplyTo($email)
106
    {
107
        $this->replyTo = Util::getFullEmail($email);
108
    }
109
110 13
    public function getCC()
111
    {
112 13
        return $this->cc;
113
    }
114
115 1
    public function setCC($email, $name = null)
116
    {
117 1
        $this->cc = [Util::getFullEmail($email, $name)];
118 1
    }
119
120 10
    public function addCC($email, $name = null)
121
    {
122 10
        $this->cc[] = Util::getFullEmail($email, $name);
123 10
    }
124
125 13
    public function getBCC()
126
    {
127 13
        return $this->bcc;
128
    }
129
130 1
    public function setBCC($email, $name = null)
131
    {
132 1
        $this->bcc = [Util::getFullEmail($email, $name)];
133 1
    }
134
135 10
    public function addBCC($email, $name = null)
136
    {
137 10
        $this->bcc[] = Util::getFullEmail($email, $name);
138 10
    }
139
140 13
    public function getBody()
141
    {
142 13
        return $this->body;
143
    }
144
145 4
    public function setBody($value)
146
    {
147 4
        $this->body = $value;
148 4
    }
149
150 13
    public function getBodyText()
151
    {
152 13
        $body = preg_replace(
153
            [
154 13
                '~<h.*?>(.*?)</h.*?>~',
155 13
                '~<div.*?>(.*?)</div>~',
156 13
                '~<p.*?>(.*?)</p>~',
157
                '~<br.*?>~'
158 13
            ],
159
            [
160 13
                "# $1\n\n",
161 13
                "$1\n",
162 13
                "$1\n",
163
                "\n"
164 13
            ],
165 13
            $this->body
166 13
        );
167
168 13
        return strip_tags($body);
169
    }
170
171 8
    public function isHtml($value = null)
172
    {
173 8
        if (!is_null($value) && is_bool($value)) {
174
            $this->isHtml = $value;
175
        }
176
177 8
        return $this->isHtml;
178
    }
179
180 13
    public function getAttachments()
181
    {
182 13
        return $this->attachment;
183
    }
184
}
185