11<?php
2+
3+ declare (strict_types=1 );
24/**
35 * Shopware 5
46 * Copyright (c) shopware AG
@@ -48,20 +50,11 @@ class LogEntryBuilder implements LogEntryBuilderInterface
4850 public const SHOP_ASSOCIATION = 'shop ' ;
4951 public const SHOP_ID_ASSOCIATION = 'shopId ' ;
5052
51- /**
52- * @var EntityManagerInterface
53- */
54- private $ entityManager ;
53+ private EntityManagerInterface $ entityManager ;
5554
56- /**
57- * @var MailRepository
58- */
59- private $ mailRepository ;
55+ private MailRepository $ mailRepository ;
6056
61- /**
62- * @var OrderRepository
63- */
64- private $ orderRepository ;
57+ private OrderRepository $ orderRepository ;
6558
6659 public function __construct (EntityManagerInterface $ entityManager )
6760 {
@@ -77,9 +70,9 @@ public function build(Enlight_Components_Mail $mail): Log
7770 {
7871 $ logEntry = new Log ();
7972
80- $ logEntry ->setSubject (iconv_mime_decode ($ mail ->getSubject ()));
73+ $ logEntry ->setSubject (( string ) iconv_mime_decode ($ mail ->getSubject ()));
8174 $ logEntry ->setSender ($ mail ->getFrom ());
82- $ logEntry ->setSentAt (new DateTime ($ mail ->getDate ()));
75+ $ logEntry ->setSentAt (new DateTime (( string ) $ mail ->getDate ()));
8376 $ logEntry ->setContentText ($ mail ->getPlainBodyText ());
8477
8578 if ($ mail ->getBodyHtml () instanceof Zend_Mime_Part) {
@@ -111,7 +104,6 @@ protected function assignType(Log $logEntry, ?string $templateName): void
111104
112105 protected function assignOrder (Log $ logEntry , Enlight_Components_Mail $ mail ): void
113106 {
114- /** @var Order|null $order */
115107 $ order = $ this ->resolveOrderByAssociation ($ mail );
116108
117109 if ($ order !== null ) {
@@ -120,7 +112,6 @@ protected function assignOrder(Log $logEntry, Enlight_Components_Mail $mail): vo
120112 return ;
121113 }
122114
123- /** @var Order|null $order */
124115 $ order = $ this ->resolveOrderByType ($ logEntry ->getType ());
125116
126117 if ($ order !== null ) {
@@ -137,7 +128,6 @@ protected function assignShop(Log $logEntry, Enlight_Components_Mail $mail): voi
137128 }
138129
139130 if ($ mail ->getAssociation (self ::SHOP_ID_ASSOCIATION ) !== null ) {
140- /** @var Shop $shop */
141131 $ shop = $ this ->entityManager ->getPartialReference (
142132 Shop::class,
143133 $ mail ->getAssociation (self ::SHOP_ID_ASSOCIATION )
@@ -227,10 +217,13 @@ protected function assignRecipients(Log $logEntry, array $recipients = []): void
227217 foreach ($ knownRecipients as $ recipient ) {
228218 unset($ unknownRecipients [$ recipient ['mail_address ' ]]);
229219
230- $ associatedContacts [] = $ this ->entityManager ->getPartialReference (
220+ $ contact = $ this ->entityManager ->getReference (
231221 Contact::class,
232222 $ recipient ['id ' ]
233223 );
224+ if ($ contact instanceof Contact) {
225+ $ associatedContacts [] = $ contact ;
226+ }
234227 }
235228
236229 foreach (array_keys ($ unknownRecipients ) as $ recipient ) {
@@ -239,13 +232,15 @@ protected function assignRecipients(Log $logEntry, array $recipients = []): void
239232
240233 $ this ->persistContact ($ contact );
241234
242- $ associatedContacts [] = $ this ->entityManager ->getPartialReference (
235+ $ fetchedContact = $ this ->entityManager ->getReference (
243236 Contact::class,
244237 $ contact ->getId ()
245238 );
239+ if ($ fetchedContact instanceof Contact) {
240+ $ associatedContacts [] = $ fetchedContact ;
241+ }
246242 }
247243
248- /** @var ArrayCollection<Contact> $collection */
249244 $ collection = new ArrayCollection ($ associatedContacts );
250245 $ logEntry ->setRecipients ($ collection );
251246 }
@@ -275,8 +270,7 @@ protected function assignDocuments(Log $logEntry, Enlight_Components_Mail $mail)
275270 return ;
276271 }
277272
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 ()]);
280274 $ filenameIdMap = [];
281275
282276 foreach ($ documents as $ document ) {
@@ -287,15 +281,15 @@ protected function assignDocuments(Log $logEntry, Enlight_Components_Mail $mail)
287281 }
288282 }
289283
290- /** @var Zend_Mime_Part $part */
291284 foreach ($ mail ->getParts () as $ part ) {
292285 if (isset ($ filenameIdMap [$ part ->filename ])) {
293- /** @var Document $document */
294286 $ document = $ this ->entityManager ->getPartialReference (
295287 Document::class,
296288 $ filenameIdMap [$ part ->filename ]
297289 );
298- $ logEntry ->addDocument ($ document );
290+ if ($ document instanceof Document) {
291+ $ logEntry ->addDocument ($ document );
292+ }
299293 }
300294 }
301295 }
0 commit comments