1
1
<?php
2
+
3
+ declare (strict_types=1 );
2
4
/**
3
5
* Shopware 5
4
6
* Copyright (c) shopware AG
@@ -48,20 +50,11 @@ class LogEntryBuilder implements LogEntryBuilderInterface
48
50
public const SHOP_ASSOCIATION = 'shop ' ;
49
51
public const SHOP_ID_ASSOCIATION = 'shopId ' ;
50
52
51
- /**
52
- * @var EntityManagerInterface
53
- */
54
- private $ entityManager ;
53
+ private EntityManagerInterface $ entityManager ;
55
54
56
- /**
57
- * @var MailRepository
58
- */
59
- private $ mailRepository ;
55
+ private MailRepository $ mailRepository ;
60
56
61
- /**
62
- * @var OrderRepository
63
- */
64
- private $ orderRepository ;
57
+ private OrderRepository $ orderRepository ;
65
58
66
59
public function __construct (EntityManagerInterface $ entityManager )
67
60
{
@@ -77,9 +70,9 @@ public function build(Enlight_Components_Mail $mail): Log
77
70
{
78
71
$ logEntry = new Log ();
79
72
80
- $ logEntry ->setSubject (iconv_mime_decode ($ mail ->getSubject ()));
73
+ $ logEntry ->setSubject (( string ) iconv_mime_decode ($ mail ->getSubject ()));
81
74
$ logEntry ->setSender ($ mail ->getFrom ());
82
- $ logEntry ->setSentAt (new DateTime ($ mail ->getDate ()));
75
+ $ logEntry ->setSentAt (new DateTime (( string ) $ mail ->getDate ()));
83
76
$ logEntry ->setContentText ($ mail ->getPlainBodyText ());
84
77
85
78
if ($ mail ->getBodyHtml () instanceof Zend_Mime_Part) {
@@ -111,7 +104,6 @@ protected function assignType(Log $logEntry, ?string $templateName): void
111
104
112
105
protected function assignOrder (Log $ logEntry , Enlight_Components_Mail $ mail ): void
113
106
{
114
- /** @var Order|null $order */
115
107
$ order = $ this ->resolveOrderByAssociation ($ mail );
116
108
117
109
if ($ order !== null ) {
@@ -120,7 +112,6 @@ protected function assignOrder(Log $logEntry, Enlight_Components_Mail $mail): vo
120
112
return ;
121
113
}
122
114
123
- /** @var Order|null $order */
124
115
$ order = $ this ->resolveOrderByType ($ logEntry ->getType ());
125
116
126
117
if ($ order !== null ) {
@@ -137,7 +128,6 @@ protected function assignShop(Log $logEntry, Enlight_Components_Mail $mail): voi
137
128
}
138
129
139
130
if ($ mail ->getAssociation (self ::SHOP_ID_ASSOCIATION ) !== null ) {
140
- /** @var Shop $shop */
141
131
$ shop = $ this ->entityManager ->getPartialReference (
142
132
Shop::class,
143
133
$ mail ->getAssociation (self ::SHOP_ID_ASSOCIATION )
@@ -227,10 +217,13 @@ protected function assignRecipients(Log $logEntry, array $recipients = []): void
227
217
foreach ($ knownRecipients as $ recipient ) {
228
218
unset($ unknownRecipients [$ recipient ['mail_address ' ]]);
229
219
230
- $ associatedContacts [] = $ this ->entityManager ->getPartialReference (
220
+ $ contact = $ this ->entityManager ->getReference (
231
221
Contact::class,
232
222
$ recipient ['id ' ]
233
223
);
224
+ if ($ contact instanceof Contact) {
225
+ $ associatedContacts [] = $ contact ;
226
+ }
234
227
}
235
228
236
229
foreach (array_keys ($ unknownRecipients ) as $ recipient ) {
@@ -239,13 +232,15 @@ protected function assignRecipients(Log $logEntry, array $recipients = []): void
239
232
240
233
$ this ->persistContact ($ contact );
241
234
242
- $ associatedContacts [] = $ this ->entityManager ->getPartialReference (
235
+ $ fetchedContact = $ this ->entityManager ->getReference (
243
236
Contact::class,
244
237
$ contact ->getId ()
245
238
);
239
+ if ($ fetchedContact instanceof Contact) {
240
+ $ associatedContacts [] = $ fetchedContact ;
241
+ }
246
242
}
247
243
248
- /** @var ArrayCollection<Contact> $collection */
249
244
$ collection = new ArrayCollection ($ associatedContacts );
250
245
$ logEntry ->setRecipients ($ collection );
251
246
}
@@ -275,8 +270,7 @@ protected function assignDocuments(Log $logEntry, Enlight_Components_Mail $mail)
275
270
return ;
276
271
}
277
272
278
- $ orderRepository = $ this ->entityManager ->getRepository (Order::class);
279
- $ documents = $ orderRepository ->getDocuments ([$ logEntry ->getOrder ()->getId ()]);
273
+ $ documents = $ this ->entityManager ->getRepository (Order::class)->getDocuments ([$ logEntry ->getOrder ()->getId ()]);
280
274
$ filenameIdMap = [];
281
275
282
276
foreach ($ documents as $ document ) {
@@ -287,15 +281,15 @@ protected function assignDocuments(Log $logEntry, Enlight_Components_Mail $mail)
287
281
}
288
282
}
289
283
290
- /** @var Zend_Mime_Part $part */
291
284
foreach ($ mail ->getParts () as $ part ) {
292
285
if (isset ($ filenameIdMap [$ part ->filename ])) {
293
- /** @var Document $document */
294
286
$ document = $ this ->entityManager ->getPartialReference (
295
287
Document::class,
296
288
$ filenameIdMap [$ part ->filename ]
297
289
);
298
- $ logEntry ->addDocument ($ document );
290
+ if ($ document instanceof Document) {
291
+ $ logEntry ->addDocument ($ document );
292
+ }
299
293
}
300
294
}
301
295
}
0 commit comments