Passed
Pull Request — master (#547)
by butschster
07:04
created

Message::setTo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Mailer;
13
14
final class Message implements MessageInterface
15
{
16
    /** @var string */
17
    private $subject;
18
19
    /** @var array */
20
    private $data;
21
22
    /** @var array */
23
    private $to = [];
24
25
    /** @var array */
26
    private $cc = [];
27
28
    /** @var array */
29
    private $bcc = [];
30
31
    /** @var string|null */
32
    private $from;
33
34
    /** @var string|null */
35
    private $replyTo;
36
37
    /** @var array */
38
    private $options = [];
39
40
    /**
41
     * @param string|string[] $to
42
     */
43
    public function __construct(string $subject, $to, array $data = [])
44
    {
45
        $this->setSubject($subject);
46
        $this->setTo(...(array)$to);
47
        $this->setData($data);
48
    }
49
50
    public function setSubject(string $subject): self
51
    {
52
        $this->subject = $subject;
53
54
        return $this;
55
    }
56
57
    public function getSubject(): string
58
    {
59
        return $this->subject;
60
    }
61
62
    public function setData(array $data): self
63
    {
64
        $this->data = $data;
65
66
        return $this;
67
    }
68
69
    public function getData(): array
70
    {
71
        return $this->data;
72
    }
73
74
    public function setTo(string ...$to): self
75
    {
76
        $this->to = $to;
77
78
        return $this;
79
    }
80
81
    public function getTo(): array
82
    {
83
        return $this->to;
84
    }
85
86
    public function setCC(string ...$cc): self
87
    {
88
        $this->cc = $cc;
89
90
        return $this;
91
    }
92
93
    public function getCC(): array
94
    {
95
        return $this->cc;
96
    }
97
98
    public function setBCC(string ...$bcc): self
99
    {
100
        $this->bcc = $bcc;
101
102
        return $this;
103
    }
104
105
    public function getBCC(): array
106
    {
107
        return $this->bcc;
108
    }
109
110
    public function setFrom(?string $from): self
111
    {
112
        $this->from = $from;
113
114
        return $this;
115
    }
116
117
    public function getFrom(): ?string
118
    {
119
        return $this->from;
120
    }
121
122
    public function setReplyTo(?string $replyTo): self
123
    {
124
        $this->replyTo = $replyTo;
125
126
        return $this;
127
    }
128
129
    public function getReplyTo(): ?string
130
    {
131
        return $this->replyTo;
132
    }
133
134
    public function setOptions(array $options): self
135
    {
136
        $this->options = $options;
137
138
        return $this;
139
    }
140
141
    /**
142
     * @param mixed $value
143
     */
144
    public function setOption(string $name, $value): self
145
    {
146
        $this->options[$name] = $value;
147
148
        return $this;
149
    }
150
151
    public function getOptions(): array
152
    {
153
        return $this->options;
154
    }
155
156
    /**
157
     * @param int|\DateTimeInterface|\DateInterval $delay
158
     */
159
    public function setDelay($delay): self
160
    {
161
        if ($delay instanceof \DateInterval) {
162
            $delay = (new \DateTimeImmutable('NOW'))->add($delay);
163
        }
164
165
        if ($delay instanceof \DateTimeInterface) {
166
            $delay = max(0, $delay->getTimestamp() - time());
167
        }
168
169
        return $this->setOption('delay', (int)$delay);
170
    }
171
}
172