Passed
Push — master ( 84a999...178a27 )
by Peter
02:14
created

Message::setFromPhone()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Contact\Domain\Entities;
6
7
use AbterPhp\Framework\Domain\Entities\IStringerEntity;
8
9
class Message implements IStringerEntity
10
{
11
    /** @var string */
12
    protected $id;
13
14
    /** @var Form */
15
    protected $form;
16
17
    /** @var string */
18
    protected $subject;
19
20
    /** @var string */
21
    protected $body;
22
23
    /** @var string */
24
    protected $fromName;
25
26
    /** @var string */
27
    protected $fromEmail;
28
29
    /** @var string|null */
30
    protected $fromPhone;
31
32
    /**
33
     * @param string      $id
34
     * @param Form        $form
35
     * @param string      $subject
36
     * @param string      $body
37
     * @param string      $fromName
38
     * @param string      $fromEmail
39
     * @param string|null $fromPhone
40
     */
41
    public function __construct(
42
        string $id,
43
        Form $form,
44
        string $subject,
45
        string $body,
46
        string $fromName,
47
        string $fromEmail,
48
        ?string $fromPhone
49
    ) {
50
        $this->id        = $id;
51
        $this->form      = $form;
52
        $this->subject   = $subject;
53
        $this->body      = $body;
54
        $this->fromName  = $fromName;
55
        $this->fromEmail = $fromEmail;
56
        $this->fromPhone = $fromPhone;
57
    }
58
59
    /**
60
     * @return string
61
     */
62
    public function getId()
63
    {
64
        return $this->id;
65
    }
66
67
    /**
68
     * @param string $id
69
     */
70
    public function setId($id)
71
    {
72
        $this->id = $id;
73
    }
74
75
    /**
76
     * @return Form
77
     */
78
    public function getForm(): Form
79
    {
80
        return $this->form;
81
    }
82
83
    /**
84
     * @param Form $form
85
     *
86
     * @return $this
87
     */
88
    public function setForm(Form $form): Message
89
    {
90
        $this->form = $form;
91
92
        return $this;
93
    }
94
95
    /**
96
     * @return string
97
     */
98
    public function getSubject(): string
99
    {
100
        return $this->subject;
101
    }
102
103
    /**
104
     * @param string $subject
105
     *
106
     * @return $this
107
     */
108
    public function setSubject(string $subject): Message
109
    {
110
        $this->subject = $subject;
111
112
        return $this;
113
    }
114
115
    /**
116
     * @return string
117
     */
118
    public function getBody(): string
119
    {
120
        return $this->body;
121
    }
122
123
    /**
124
     * @param string $body
125
     *
126
     * @return $this
127
     */
128
    public function setBody(string $body): Message
129
    {
130
        $this->body = $body;
131
132
        return $this;
133
    }
134
135
    /**
136
     * @return string
137
     */
138
    public function getFromName(): string
139
    {
140
        return $this->fromName;
141
    }
142
143
    /**
144
     * @param string $fromName
145
     *
146
     * @return $this
147
     */
148
    public function setFromName(string $fromName): Message
149
    {
150
        $this->fromName = $fromName;
151
152
        return $this;
153
    }
154
155
    /**
156
     * @return string
157
     */
158
    public function getFromEmail(): string
159
    {
160
        return $this->fromEmail;
161
    }
162
163
    /**
164
     * @param string $fromEmail
165
     *
166
     * @return $this
167
     */
168
    public function setFromEmail(string $fromEmail): Message
169
    {
170
        $this->fromEmail = $fromEmail;
171
172
        return $this;
173
    }
174
175
    /**
176
     * @return string|null
177
     */
178
    public function getFromPhone(): ?string
179
    {
180
        return $this->fromPhone;
181
    }
182
183
    /**
184
     * @param string|null $fromPhone
185
     *
186
     * @return $this
187
     */
188
    public function setFromPhone(?string $fromPhone): Message
189
    {
190
        $this->fromPhone = empty($fromPhone) ? null : $fromPhone;
191
192
        return $this;
193
    }
194
195
    /**
196
     * @return string
197
     */
198
    public function __toString(): string
199
    {
200
        return sprintf('%s - %s', $this->getFromName(), $this->getSubject());
201
    }
202
203
    /**
204
     * @return array|null
205
     */
206
    public function toData(): ?array
207
    {
208
        return [
209
            'id'         => $this->getId(),
210
            'form'       => $this->getForm(),
211
            'subject'    => $this->getSubject(),
212
            'body'       => $this->getBody(),
213
            'from_name'  => $this->getFromName(),
214
            'from_email' => $this->getFromEmail(),
215
            'from_phone' => $this->getFromPhone(),
216
        ];
217
    }
218
219
    /**
220
     * @return string
221
     */
222
    public function toJSON(): string
223
    {
224
        return json_encode($this->toData());
225
    }
226
}
227