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.

Message::setMetadata()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
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 implements ExtendedMessage
16
{
17
    use OptionsSanitizingCapabilities;
18
19
    /**
20
     * @var string
21
     */
22
    private $campaignId;
23
24
    /**
25
     * @var array
26
     */
27
    private $perRecipientTags;
28
29
    /**
30
     * @var array
31
     */
32
    private $metadata;
33
34
    /**
35
     * @var array
36
     */
37
    private $perRecipientMetadata;
38
39
    /**
40
     * @var array
41
     */
42
    private $substitutionData;
43
44
    /**
45
     * @var array
46
     */
47
    private $perRecipientSubstitutionData;
48
49
    /**
50
     * @var array
51
     */
52
    private $options;
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 21
    public static function newInstance($subject = null, $body = null, $contentType = null, $charset = null)
58
    {
59 21
        return new self($subject, $body, $contentType, $charset);
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 60
    public function __construct($subject = null, $body = null, $contentType = null, $charset = null)
66
    {
67 60
        parent::__construct($subject, $body, $contentType, $charset);
68
69 60
        $this->campaignId                   = '';
70 60
        $this->perRecipientTags             = [];
71 60
        $this->metadata                     = [];
72 60
        $this->perRecipientMetadata         = [];
73 60
        $this->substitutionData             = [];
74 60
        $this->perRecipientSubstitutionData = [];
75 60
        $this->options                      = [];
76 60
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81 21
    public function getCampaignId()
82
    {
83 21
        return $this->campaignId;
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89 6
    public function setCampaignId($campaignId)
90
    {
91 6
        $this->campaignId = $campaignId;
92
93 6
        return $this;
94
    }
95
96
    /**
97
     * {@inheritdoc}
98
     */
99 21
    public function getPerRecipientTags()
100
    {
101 21
        return $this->perRecipientTags;
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107 12
    public function setPerRecipientTags($recipient, array $tags)
108
    {
109 12
        $this->perRecipientTags[(string) $recipient] = $this->sanitizeTags($tags);
110
111 12
        return $this;
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117 21
    public function getMetadata()
118
    {
119 21
        return $this->metadata;
120
    }
121
122
    /**
123
     * {@inheritdoc}
124
     */
125 12
    public function setMetadata(array $metadata)
126
    {
127 12
        $this->metadata = $this->sanitizeMetadata($metadata);
128
129 6
        return $this;
130
    }
131
132
    /**
133
     * {@inheritdoc}
134
     */
135 21
    public function getPerRecipientMetadata()
136
    {
137 21
        return $this->perRecipientMetadata;
138
    }
139
140
    /**
141
     * {@inheritdoc}
142
     */
143 18
    public function setPerRecipientMetadata($recipient, array $metadata)
144
    {
145 18
        $this->perRecipientMetadata[(string) $recipient] = $this->sanitizeMetadata($metadata);
146
147 12
        return $this;
148
    }
149
150
    /**
151
     * {@inheritdoc}
152
     */
153 21
    public function getSubstitutionData()
154
    {
155 21
        return $this->substitutionData;
156
    }
157
158
    /**
159
     * {@inheritdoc}
160
     */
161 6
    public function setSubstitutionData(array $substitutionData)
162
    {
163 6
        $this->substitutionData = $this->sanitizeSubstitutionData($substitutionData);
164
165 6
        return $this;
166
    }
167
168
    /**
169
     * {@inheritdoc}
170
     */
171 21
    public function getPerRecipientSubstitutionData()
172
    {
173 21
        return $this->perRecipientSubstitutionData;
174
    }
175
176
    /**
177
     * {@inheritdoc}
178
     */
179 12
    public function setPerRecipientSubstitutionData($recipient, array $substitutionData)
180
    {
181 12
        $this->perRecipientSubstitutionData[(string) $recipient] = $this->sanitizeSubstitutionData($substitutionData);
182
183 12
        return $this;
184
    }
185
186
    /**
187
     * {@inheritdoc}
188
     */
189 24
    public function getOptions()
190
    {
191 24
        return $this->options;
192
    }
193
194
    /**
195
     * {@inheritdoc}
196
     */
197 15
    public function setOptions(array $options)
198
    {
199 15
        $this->options = array_merge(
200 15
            $this->options,
201 15
            $this->sanitizeOptions($options)
202 4
        );
203
204 12
        return $this;
205
    }
206
207
    /**
208
     * @param array $tags
209
     *
210
     * @return array
211
     */
212 12
    private function sanitizeTags(array $tags)
213
    {
214 12
        $sanitized = [];
215
216 12
        foreach ($tags as $tag) {
217 12
            $sanitized[] = (string) $tag;
218 4
        }
219
220 12
        return $sanitized;
221
    }
222
223
    /**
224
     * @param array $metadata
225
     *
226
     * @return array
227
     */
228 24
    private function sanitizeMetadata(array $metadata)
229
    {
230 24
        array_walk_recursive(
231 24
            $metadata,
232 24
            function ($value) {
233 24
                if (is_object($value) || is_resource($value)) {
234 12
                    throw new Exception('Metadata cannot contain objects or resources');
235
                }
236 20
            }
237 8
        );
238
239 12
        return $metadata;
240
    }
241
242
    /**
243
     * @param array $substitutionData
244
     *
245
     * @return array
246
     */
247 12
    private function sanitizeSubstitutionData(array $substitutionData)
248
    {
249 12
        $sanitized = [];
250
251 12
        foreach ($substitutionData as $key => $value) {
252 12
            $sanitized[(string) $key] = (string) $value;
253 4
        }
254
255 12
        return $sanitized;
256
    }
257
}
258