29
29
use Symfony \Contracts \HttpClient \Exception \TransportExceptionInterface ;
30
30
use Symfony \Contracts \HttpClient \HttpClientInterface ;
31
31
use Symfony \Contracts \HttpClient \ResponseInterface ;
32
- use Symfony \Contracts \Translation \TranslatorInterface ;
33
32
34
33
class SparkpostTransport extends AbstractApiTransport implements TokenTransportInterface
35
34
{
@@ -55,8 +54,7 @@ class SparkpostTransport extends AbstractApiTransport implements TokenTransportI
55
54
56
55
public function __construct (
57
56
private string $ apiKey ,
58
- private string $ region ,
59
- private TranslatorInterface $ translator ,
57
+ string $ region ,
60
58
private TransportCallback $ callback ,
61
59
HttpClientInterface $ client = null ,
62
60
EventDispatcherInterface $ dispatcher = null ,
@@ -81,30 +79,33 @@ public function __toString(): string
81
79
protected function doSendApi (SentMessage $ sentMessage , Email $ email , Envelope $ envelope ): ResponseInterface
82
80
{
83
81
try {
84
- $ payload = $ this ->getSparkPostPayload ($ sentMessage );
82
+ $ payload = $ this ->getSparkpostPayload ($ sentMessage );
85
83
$ this ->checkTemplateIsValid ($ payload );
86
- $ response = $ this ->getSparkPostResponse ('transmissions ' , $ payload );
84
+ $ response = $ this ->getSparkpostResponse ('transmissions ' , $ payload );
87
85
$ this ->handleError ($ response );
88
86
89
87
if ($ errorMessage = $ this ->getErrorMessageFromResponseBody ($ response ->toArray ())) {
90
88
/** @var MauticMessage $message */
91
89
$ message = $ sentMessage ->getOriginalMessage ();
92
90
$ this ->processImmediateSendFeedback ($ payload , $ response ->toArray (), $ message ->getMetadata ());
93
- $ this -> throwException ($ errorMessage );
91
+ throw new TransportException ($ errorMessage );
94
92
}
95
93
96
94
return $ response ;
97
95
} catch (\Exception $ e ) {
98
- $ this -> throwException ($ e ->getMessage ());
96
+ throw new TransportException ($ e ->getMessage ());
99
97
}
100
98
}
101
99
102
- private function getSparkPostPayload (SentMessage $ message ): array
100
+ /**
101
+ * @return array<mixed>
102
+ */
103
+ private function getSparkpostPayload (SentMessage $ message ): array
103
104
{
104
105
$ email = $ message ->getOriginalMessage ();
105
106
106
107
if (!$ email instanceof MauticMessage) {
107
- $ this -> throwException ('Message must be an instance of ' .MauticMessage::class);
108
+ throw new TransportException ('Message must be an instance of ' .MauticMessage::class);
108
109
}
109
110
110
111
$ metadata = $ email ->getMetadata ();
@@ -147,11 +148,9 @@ private function getSparkPostPayload(SentMessage $message): array
147
148
];
148
149
}
149
150
150
- private function throwException (string $ message ): void
151
- {
152
- throw new TransportException ($ message );
153
- }
154
-
151
+ /**
152
+ * @return array<mixed>
153
+ */
155
154
private function buildContent (MauticMessage $ message ): array
156
155
{
157
156
$ fromAddress = current ($ message ->getFrom ());
@@ -169,6 +168,9 @@ private function buildContent(MauticMessage $message): array
169
168
];
170
169
}
171
170
171
+ /**
172
+ * @return array<mixed>
173
+ */
172
174
private function buildHeaders (MauticMessage $ message ): array
173
175
{
174
176
$ result = [];
@@ -183,6 +185,9 @@ private function buildHeaders(MauticMessage $message): array
183
185
return $ result ;
184
186
}
185
187
188
+ /**
189
+ * @return array<mixed>
190
+ */
186
191
private function buildAttachments (MauticMessage $ message ): array
187
192
{
188
193
$ result = [];
@@ -203,6 +208,9 @@ private function buildAttachments(MauticMessage $message): array
203
208
return $ result ;
204
209
}
205
210
211
+ /**
212
+ * @return array<mixed>
213
+ */
206
214
private function buildRecipients (MauticMessage $ message , array $ metadata , array $ mergeVars ): array
207
215
{
208
216
$ recipients = [];
@@ -226,6 +234,9 @@ private function buildRecipients(MauticMessage $message, array $metadata, array
226
234
return $ recipients ;
227
235
}
228
236
237
+ /**
238
+ * @return array<mixed>
239
+ */
229
240
private function buildRecipient (Address $ to , array $ metadata , array $ mergeVars ): array
230
241
{
231
242
$ recipient = [
@@ -265,6 +276,9 @@ private function buildRecipient(Address $to, array $metadata, array $mergeVars):
265
276
return $ recipient ;
266
277
}
267
278
279
+ /**
280
+ * @return array<mixed>
281
+ */
268
282
private function buildCopyRecipient (Address $ to , Address $ copy , array $ recipient ): array
269
283
{
270
284
$ copyRecipient = [
@@ -317,7 +331,7 @@ private function checkTemplateIsValid(array $payload): void
317
331
unset($ payload ['recipients ' ]);
318
332
}
319
333
320
- $ response = $ this ->getSparkPostResponse ('utils/content-previewer ' , $ payload );
334
+ $ response = $ this ->getSparkpostResponse ('utils/content-previewer ' , $ payload );
321
335
322
336
if (403 === $ response ->getStatusCode ()) {
323
337
// We cannot fail as it would be a BC break. Throw a warning and continue.
@@ -333,7 +347,7 @@ private function checkTemplateIsValid(array $payload): void
333
347
/**
334
348
* @throws TransportExceptionInterface
335
349
*/
336
- private function getSparkPostResponse (
350
+ private function getSparkpostResponse (
337
351
string $ endpoint ,
338
352
array $ payload ,
339
353
string $ method = Request::METHOD_POST
@@ -364,7 +378,7 @@ private function handleError(ResponseInterface $response): void
364
378
}
365
379
366
380
$ data = json_decode ($ response ->getContent (false ), true );
367
- $ this ->getLogger ()->error ('SparkPostApiTransport error response ' , $ data );
381
+ $ this ->getLogger ()->error ('SparkpostApiTransport error response ' , $ data );
368
382
369
383
throw new HttpTransportException (json_encode ($ data ['errors ' ]), $ response , $ response ->getStatusCode ());
370
384
}
0 commit comments