GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( 3d5dc4...404a4d )
by Jasper
06:53
created

Message::getSubstitutionData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * @license https://github.com/f500/swiftmailer-sparkpost/blob/master/LICENSE Proprietary
5
 */
6
7
namespace SwiftSparkPost;
8
9
use Swift_Message;
10
11
/**
12
 * @copyright Future500 B.V.
13
 * @author    Jasper N. Brouwer <[email protected]>
14
 */
15
final class Message extends Swift_Message
16
{
17
    /**
18
     * @var string
19
     */
20
    private $campaignId;
21
22
    /**
23
     * @var array
24
     */
25
    private $perRecipientTags;
26
27
    /**
28
     * @var array
29
     */
30
    private $metadata;
31
32
    /**
33
     * @var array
34
     */
35
    private $perRecipientMetadata;
36
37
    /**
38
     * @var array
39
     */
40
    private $substitutionData;
41
42
    /**
43
     * @var array
44
     */
45
    private $perRecipientSubstitutionData;
46
47
    /**
48
     * @var array
49
     */
50
    private $options;
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 21
    public static function newInstance($subject = null, $body = null, $contentType = null, $charset = null)
56
    {
57 21
        return new self($subject, $body, $contentType, $charset);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 57
    public function __construct($subject = null, $body = null, $contentType = null, $charset = null)
64
    {
65 57
        parent::__construct($subject, $body, $contentType, $charset);
66
67 57
        $this->campaignId                   = '';
68 57
        $this->perRecipientTags             = [];
69 57
        $this->metadata                     = [];
70 57
        $this->perRecipientMetadata         = [];
71 57
        $this->substitutionData             = [];
72 57
        $this->perRecipientSubstitutionData = [];
73 57
        $this->options                      = [];
74 57
    }
75
76
    /**
77
     * @return string
78
     */
79 21
    public function getCampaignId()
80
    {
81 21
        return $this->campaignId;
82
    }
83
84
    /**
85
     * @param string $campaignId
86
     *
87
     * @return Message
88
     */
89 6
    public function setCampaignId($campaignId)
90
    {
91 6
        $this->campaignId = $campaignId;
92
93 6
        return $this;
94
    }
95
96
    /**
97
     * @return array
98
     */
99 21
    public function getPerRecipientTags()
100
    {
101 21
        return $this->perRecipientTags;
102
    }
103
104
    /**
105
     * @param string $recipient
106
     * @param array  $tags
107
     *
108
     * @return Message
109
     */
110 12
    public function setPerRecipientTags($recipient, array $tags)
111
    {
112 12
        $this->perRecipientTags[(string) $recipient] = $this->sanitizeTags($tags);
113
114 12
        return $this;
115
    }
116
117
    /**
118
     * @return array
119
     */
120 21
    public function getMetadata()
121
    {
122 21
        return $this->metadata;
123
    }
124
125
    /**
126
     * @param array $metadata
127
     *
128
     * @return Message
129
     */
130 12
    public function setMetadata(array $metadata)
131
    {
132 12
        $this->metadata = $this->sanitizeMetadata($metadata);
133
134 6
        return $this;
135
    }
136
137
    /**
138
     * @return array
139
     */
140 21
    public function getPerRecipientMetadata()
141
    {
142 21
        return $this->perRecipientMetadata;
143
    }
144
145
    /**
146
     * @param string $recipient
147
     * @param array  $metadata
148
     *
149
     * @return Message
150
     */
151 18
    public function setPerRecipientMetadata($recipient, array $metadata)
152
    {
153 18
        $this->perRecipientMetadata[(string) $recipient] = $this->sanitizeMetadata($metadata);
154
155 12
        return $this;
156
    }
157
158
    /**
159
     * @return array
160
     */
161 21
    public function getSubstitutionData()
162
    {
163 21
        return $this->substitutionData;
164
    }
165
166
    /**
167
     * @param array $substitutionData
168
     *
169
     * @return Message
170
     */
171 6
    public function setSubstitutionData(array $substitutionData)
172
    {
173 6
        $this->substitutionData = $this->sanitizeSubstitutionData($substitutionData);
174
175 6
        return $this;
176
    }
177
178
    /**
179
     * @return array
180
     */
181 21
    public function getPerRecipientSubstitutionData()
182
    {
183 21
        return $this->perRecipientSubstitutionData;
184
    }
185
186
    /**
187
     * @param string $recipient
188
     * @param array  $substitutionData
189
     *
190
     * @return Message
191
     */
192 12
    public function setPerRecipientSubstitutionData($recipient, array $substitutionData)
193
    {
194 12
        $this->perRecipientSubstitutionData[(string) $recipient] = $this->sanitizeSubstitutionData($substitutionData);
195
196 12
        return $this;
197
    }
198
199
    /**
200
     * @return array
201
     */
202 21
    public function getOptions()
203
    {
204 21
        return $this->options;
205
    }
206
207
    /**
208
     * @param array $options
209
     *
210
     * @return Message
211
     */
212 12 View Code Duplication
    public function setOptions(array $options)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
213
    {
214 12
        Configuration::guardOptionValidity($options);
215
216 9
        foreach ($options as $option => $value) {
217 9
            if ($option === Configuration::OPT_IP_POOL) {
218 9
                $this->options[$option] = (string) $value;
219 9
                continue;
220
            }
221
222 9
            $this->options[$option] = (bool) $value;
223 3
        }
224
225 9
        return $this;
226
    }
227
228
    /**
229
     * @param array $tags
230
     *
231
     * @return array
232
     */
233 12
    private function sanitizeTags(array $tags)
234
    {
235 12
        $sanitized = [];
236
237 12
        foreach ($tags as $tag) {
238 12
            $sanitized[] = (string) $tag;
239 4
        }
240
241 12
        return $sanitized;
242
    }
243
244
    /**
245
     * @param array $metadata
246
     *
247
     * @return array
248
     */
249 24
    private function sanitizeMetadata(array $metadata)
250
    {
251 24
        array_walk_recursive(
252 8
            $metadata,
253 24
            function ($value) {
254 24
                if (is_object($value) || is_resource($value)) {
255 12
                    throw new Exception('Metadata cannot contain objects or resources');
256
                }
257 20
            }
258 8
        );
259
260 12
        return $metadata;
261
    }
262
263
    /**
264
     * @param array $substitutionData
265
     *
266
     * @return array
267
     */
268 12
    private function sanitizeSubstitutionData(array $substitutionData)
269
    {
270 12
        $sanitized = [];
271
272 12
        foreach ($substitutionData as $key => $value) {
273 12
            $sanitized[(string) $key] = (string) $value;
274 4
        }
275
276 12
        return $sanitized;
277
    }
278
}
279