Skip to content

Commit cd11bda

Browse files
committed
MC-15295: Changes from review
1 parent 6f8b8b8 commit cd11bda

File tree

6 files changed

+43
-43
lines changed

6 files changed

+43
-43
lines changed

app/code/Magento/Newsletter/Model/Queue/TransportBuilder.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function __construct(
119119
*/
120120
public function addCc($address, $name = '')
121121
{
122-
$this->getMailAddresses('cc', $address, $name);
122+
$this->addAddressByType('cc', $address, $name);
123123

124124
return $this;
125125
}
@@ -135,7 +135,7 @@ public function addCc($address, $name = '')
135135
*/
136136
public function addTo($address, $name = '')
137137
{
138-
$this->getMailAddresses('to', $address, $name);
138+
$this->addAddressByType('to', $address, $name);
139139

140140
return $this;
141141
}
@@ -150,7 +150,7 @@ public function addTo($address, $name = '')
150150
*/
151151
public function addBcc($address)
152152
{
153-
$this->getMailAddresses('bcc', $address);
153+
$this->addAddressByType('bcc', $address);
154154

155155
return $this;
156156
}
@@ -167,7 +167,7 @@ public function addBcc($address)
167167
public function setReplyTo($email, $name = null)
168168
{
169169

170-
$this->getMailAddresses('replyTo', $email, $name);
170+
$this->addAddressByType('replyTo', $email, $name);
171171

172172
return $this;
173173
}
@@ -201,7 +201,7 @@ public function setFrom($from)
201201
public function setFromByScope($from, $scopeId = null)
202202
{
203203
$result = $this->_senderResolver->resolve($from, $scopeId);
204-
$this->getMailAddresses('from', $result['email'], $result['name']);
204+
$this->addAddressByType('from', $result['email'], $result['name']);
205205

206206
return $this;
207207
}
@@ -273,22 +273,22 @@ protected function prepareMessage()
273273
* Handles possible incoming types of email (string or array)
274274
*
275275
* @param string $addressType
276-
* @param string|array $emailOrList
276+
* @param string|array $email
277277
* @param string|null $name
278278
*
279279
* @return void
280280
* @throws MailException
281281
*/
282-
private function getMailAddresses(string $addressType, $emailOrList, ?string $name = null): void
282+
private function addAddressByType(string $addressType, $email, ?string $name = null): void
283283
{
284-
if (is_array($emailOrList)) {
284+
if (is_array($email)) {
285285
$this->messageData[$addressType] = array_merge(
286286
$this->messageData[$addressType],
287-
$this->addressConverter->convertMany($emailOrList)
287+
$this->addressConverter->convertMany($email)
288288
);
289289

290290
return;
291291
}
292-
$this->messageData[$addressType][] = $this->addressConverter->convert($emailOrList, $name);
292+
$this->messageData[$addressType][] = $this->addressConverter->convert($email, $name);
293293
}
294294
}

lib/internal/Magento/Framework/Mail/AddressConverter.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
<?php
22
/**
3-
* Copyright (c) 2019 TechDivision GmbH
4-
* All rights reserved
5-
*
6-
* This product includes proprietary software developed at TechDivision GmbH, Germany
7-
* For more information see https://www.techdivision.com/
8-
*
9-
* To obtain a valid license for using this software please contact us at
10-
* license@techdivision.com
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
115
*/
126
declare(strict_types=1);
137

lib/internal/Magento/Framework/Mail/EmailMessage.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,19 @@ public function __construct(
8181
throw new MailException(__('Email message must have at list one addressee'));
8282
}
8383
$this->message->setTo(
84-
$this->convertMailAddressArrayToZendAddressList($to)
84+
$this->convertAddressArrayToAddressList($to)
8585
);
8686
$this->message->setReplyTo(
87-
$this->convertMailAddressArrayToZendAddressList($replyTo)
87+
$this->convertAddressArrayToAddressList($replyTo)
8888
);
8989
$this->message->setFrom(
90-
$this->convertMailAddressArrayToZendAddressList($from)
90+
$this->convertAddressArrayToAddressList($from)
9191
);
9292
$this->message->setCc(
93-
$this->convertMailAddressArrayToZendAddressList($cc)
93+
$this->convertAddressArrayToAddressList($cc)
9494
);
9595
$this->message->setBcc(
96-
$this->convertMailAddressArrayToZendAddressList($bcc)
96+
$this->convertAddressArrayToAddressList($bcc)
9797
);
9898
$this->mimeMessageFactory = $mimeMessageFactory;
9999
$this->addressFactory = $addressFactory;
@@ -120,39 +120,39 @@ public function getHeaders(): array
120120
*/
121121
public function getFrom(): ?array
122122
{
123-
return $this->convertAddressListToMailAddressList($this->message->getFrom());
123+
return $this->convertAddressListToAddressArray($this->message->getFrom());
124124
}
125125

126126
/**
127127
* @inheritDoc
128128
*/
129129
public function getTo(): array
130130
{
131-
return $this->convertAddressListToMailAddressList($this->message->getTo());
131+
return $this->convertAddressListToAddressArray($this->message->getTo());
132132
}
133133

134134
/**
135135
* @inheritDoc
136136
*/
137137
public function getCc(): ?array
138138
{
139-
return $this->convertAddressListToMailAddressList($this->message->getCc());
139+
return $this->convertAddressListToAddressArray($this->message->getCc());
140140
}
141141

142142
/**
143143
* @inheritDoc
144144
*/
145145
public function getBcc(): ?array
146146
{
147-
return $this->convertAddressListToMailAddressList($this->message->getBcc());
147+
return $this->convertAddressListToAddressArray($this->message->getBcc());
148148
}
149149

150150
/**
151151
* @inheritDoc
152152
*/
153153
public function getReplyTo(): ?array
154154
{
155-
return $this->convertAddressListToMailAddressList($this->message->getReplyTo());
155+
return $this->convertAddressListToAddressArray($this->message->getReplyTo());
156156
}
157157

158158
/**
@@ -221,7 +221,7 @@ public function toString(): string
221221
* @param AddressList $addressList
222222
* @return Address[]
223223
*/
224-
private function convertAddressListToMailAddressList(AddressList $addressList): array
224+
private function convertAddressListToAddressArray(AddressList $addressList): array
225225
{
226226
$arrayList = [];
227227
foreach ($addressList as $address) {
@@ -243,7 +243,7 @@ private function convertAddressListToMailAddressList(AddressList $addressList):
243243
* @param Address[] $arrayList
244244
* @return AddressList
245245
*/
246-
private function convertMailAddressArrayToZendAddressList(array $arrayList): AddressList
246+
private function convertAddressArrayToAddressList(array $arrayList): AddressList
247247
{
248248
$zendAddressList = new AddressList();
249249
foreach ($arrayList as $address) {

lib/internal/Magento/Framework/Mail/MimePart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function __construct(
5757
) {
5858
try {
5959
$this->mimePart = new ZendMimePart($content);
60-
} catch (\Zend\Mime\Exception\InvalidArgumentException $e) {
60+
} catch (\Exception $e) {
6161
throw new MailException(__($e->getMessage()));
6262
}
6363
$this->mimePart->setType($type);

lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function __construct(
181181
*/
182182
public function addCc($address, $name = '')
183183
{
184-
$this->getMailAddresses('cc', $address, $name);
184+
$this->addAddressByType('cc', $address, $name);
185185

186186
return $this;
187187
}
@@ -197,7 +197,7 @@ public function addCc($address, $name = '')
197197
*/
198198
public function addTo($address, $name = '')
199199
{
200-
$this->getMailAddresses('to', $address, $name);
200+
$this->addAddressByType('to', $address, $name);
201201

202202
return $this;
203203
}
@@ -212,7 +212,7 @@ public function addTo($address, $name = '')
212212
*/
213213
public function addBcc($address)
214214
{
215-
$this->getMailAddresses('bcc', $address);
215+
$this->addAddressByType('bcc', $address);
216216

217217
return $this;
218218
}
@@ -228,7 +228,7 @@ public function addBcc($address)
228228
*/
229229
public function setReplyTo($email, $name = null)
230230
{
231-
$this->getMailAddresses('replyTo', $email, $name);
231+
$this->addAddressByType('replyTo', $email, $name);
232232

233233
return $this;
234234
}
@@ -262,7 +262,7 @@ public function setFrom($from)
262262
public function setFromByScope($from, $scopeId = null)
263263
{
264264
$result = $this->_senderResolver->resolve($from, $scopeId);
265-
$this->getMailAddresses('from', $result['email'], $result['name']);
265+
$this->addAddressByType('from', $result['email'], $result['name']);
266266

267267
return $this;
268268
}
@@ -389,8 +389,10 @@ protected function prepareMessage()
389389
new Phrase('Unknown template type')
390390
);
391391
}
392-
$this->messageData['body'] = $this->mimeMessageInterfaceFactory
393-
->create(['parts' => [$this->mimePartInterfaceFactory->create(['content'=>$content])]]);
392+
$mimePart = $this->mimePartInterfaceFactory->create(['content' => $content]);
393+
$this->messageData['body'] = $this->mimeMessageInterfaceFactory->create(
394+
['parts' => [$mimePart]]
395+
);
394396

395397
$this->messageData['subject'] = html_entity_decode(
396398
(string)$template->getSubject(),
@@ -405,22 +407,22 @@ protected function prepareMessage()
405407
* Handles possible incoming types of email (string or array)
406408
*
407409
* @param string $addressType
408-
* @param string|array $emailOrList
410+
* @param string|array $email
409411
* @param string|null $name
410412
*
411413
* @return void
412414
* @throws MailException
413415
*/
414-
private function getMailAddresses(string $addressType, $emailOrList, ?string $name = null): void
416+
private function addAddressByType(string $addressType, $email, ?string $name = null): void
415417
{
416-
if (is_array($emailOrList)) {
418+
if (is_array($email)) {
417419
$this->messageData[$addressType] = array_merge(
418420
$this->messageData[$addressType],
419-
$this->addressConverter->convertMany($emailOrList)
421+
$this->addressConverter->convertMany($email)
420422
);
421423

422424
return;
423425
}
424-
$this->messageData[$addressType][] = $this->addressConverter->convert($emailOrList, $name);
426+
$this->messageData[$addressType][] = $this->addressConverter->convert($email, $name);
425427
}
426428
}

lib/internal/Magento/Framework/Mail/Test/Unit/Template/TransportBuilderTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ class TransportBuilderTest extends \PHPUnit\Framework\TestCase
6060
* @var \Magento\Framework\Mail\EmailMessageInterface|\PHPUnit\Framework\MockObject\MockObject
6161
*/
6262
private $emailMessageMock;
63+
/**
64+
* @var \PHPUnit\Framework\MockObject\MockObject
65+
*/
66+
private $mimePartFactoryMock;
6367

6468
/**
6569
* @return void

0 commit comments

Comments
 (0)