Completed
Push — master ( 29019e...9185b8 )
by Nate
02:27 queued 01:01
created

EmailByKey::setParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
nc 1
cc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipboxfactory/craft-ember/blob/master/LICENSE
6
 * @link       https://github.com/flipboxfactory/craft-ember/
7
 */
8
9
namespace flipbox\craft\ember\queue;
10
11
use Craft;
12
use craft\elements\User;
13
use craft\helpers\ArrayHelper;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 2.3.2
18
 */
19
class EmailByKey extends AbstractEmailByKey implements \Serializable
20
{
21
    /**
22
     *  The email key
23
     *
24
     * @var string
25
     */
26
    public $key;
27
28
    /**
29
     * The recipients
30
     *
31
     * @var array
32
     */
33
    protected $recipients = [];
34
35
    /**
36
     * The email params
37
     *
38
     * @var array
39
     */
40
    protected $params;
41
42
    /**
43
     * @inheritdoc
44
     */
45
    public function getKey(): string
46
    {
47
        return $this->key;
48
    }
49
50
    /**
51
     * @inheritdoc
52
     */
53
    public function getRecipients(): array
54
    {
55
        return $this->recipients;
56
    }
57
58
    /**
59
     * @param array $recipients
60
     * @return $this
61
     */
62
    public function setRecipients(array $recipients)
63
    {
64
        foreach ($recipients as $recipient) {
65
            $this->addRecipient($recipient);
66
        }
67
        return $this;
68
    }
69
70
    /**
71
     * @param $recipient
72
     * @return $this
73
     */
74
    public function addRecipient($recipient)
75
    {
76
        if ($recipient instanceof User) {
77
            $recipient = [$recipient->email];
78
        }
79
80
        $this->recipients[] = $recipient;
81
        return $this;
82
    }
83
84
    /**
85
     * @inheritdoc
86
     */
87
    public function getParams(): array
88
    {
89
        return $this->params;
90
    }
91
92
    /**
93
     * @param $params
94
     * @return $this
95
     */
96
    public function setParams($params)
97
    {
98
        $this->params = ArrayHelper::toArray($params);
99
        return $this;
100
    }
101
102
    /**
103
     * @inheritdoc
104
     */
105
    public function serialize()
106
    {
107
        return serialize([
108
            'key' => $this->key,
109
            'recipients' => $this->recipients,
110
            'params' => $this->params
111
        ]);
112
    }
113
114
    /**
115
     * @inheritdoc
116
     */
117
    public function unserialize($serialized)
118
    {
119
        Craft::configure(
120
            $this,
121
            unserialize($serialized)
122
        );
123
    }
124
}
125