Skip to content

Commit eb9baad

Browse files
committed
MC-15295: Refactoring Exceptions
1 parent 82f74c0 commit eb9baad

File tree

7 files changed

+40
-17
lines changed

7 files changed

+40
-17
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Magento\Framework\Mail;
99

10-
use Magento\Framework\Exception\MailException;
10+
use Magento\Framework\Mail\Exception\InvalidArgumentException;
1111

1212
/**
1313
* Class AddressConverter
@@ -54,7 +54,7 @@ public function convert(string $email, ?string $name = null): Address
5454
* @param array $addresses
5555
*
5656
* @return Address[]
57-
* @throws MailException
57+
* @throws InvalidArgumentException
5858
*/
5959
public function convertMany(array $addresses): array
6060
{
@@ -67,7 +67,7 @@ public function convertMany(array $addresses): array
6767
}
6868

6969
if (!is_string($key)) {
70-
throw new MailException(
70+
throw new InvalidArgumentException(
7171
__(
7272
'Invalid key type in provided addresses array ("%1")',
7373
(is_object($key) ? get_class($key) : var_export($key, 1))

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Magento\Framework\Mail;
99

10-
use Magento\Framework\Exception\MailException;
10+
use Magento\Framework\Mail\Exception\InvalidArgumentException;
1111
use Zend\Mail\Address as ZendAddress;
1212
use Zend\Mail\AddressList;
1313
use Zend\Mail\Message as ZendMessage;
@@ -47,8 +47,8 @@ class EmailMessage implements EmailMessageInterface
4747
* @param Address|null $sender
4848
* @param string|null $subject
4949
* @param string|null $encoding
50+
* @throws InvalidArgumentException
5051
*
51-
* @throws MailException
5252
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
5353
* @SuppressWarnings(PHPMD.NPathComplexity)
5454
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
@@ -80,7 +80,7 @@ public function __construct(
8080
$this->message->setSender($sender->getEmail(), $sender->getName());
8181
}
8282
if (count($to) < 1) {
83-
throw new MailException(__('Email message must have at list one addressee'));
83+
throw new InvalidArgumentException(__('Email message must have at list one addressee'));
8484
}
8585
if ($to) {
8686
$this->message->setTo($this->convertAddressArrayToAddressList($to));
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
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
11+
*/
12+
declare(strict_types=1);
13+
14+
namespace Magento\Framework\Mail\Exception;
15+
16+
/**
17+
* Class InvalidArgumentException
18+
*/
19+
class InvalidArgumentException extends \InvalidArgumentException
20+
{
21+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
namespace Magento\Framework\Mail;
99

10-
use Magento\Framework\Exception\MailException;
10+
use Magento\Framework\Mail\Exception\InvalidArgumentException;
1111
use Zend\Mime\Part as ZendMimePart;
1212

1313
/**
14-
* Class MimePart
14+
* @inheritDoc
1515
*/
1616
class MimePart implements MimePartInterface
1717
{
@@ -39,7 +39,7 @@ class MimePart implements MimePartInterface
3939
* @SuppressWarnings(PHPMD.NPathComplexity)
4040
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
4141
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
42-
* @throws MailException
42+
* @throws InvalidArgumentException
4343
*/
4444
public function __construct(
4545
$content,
@@ -58,7 +58,7 @@ public function __construct(
5858
try {
5959
$this->mimePart = new ZendMimePart($content);
6060
} catch (\Exception $e) {
61-
throw new MailException(__($e->getMessage()));
61+
throw new InvalidArgumentException(__($e->getMessage()));
6262
}
6363
$this->mimePart->setType($type);
6464
$this->mimePart->setEncoding($encoding);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Magento\Framework\Mail;
88

99
/**
10-
* Interface MimePartInterface
10+
* Interface representing a MIME part.
1111
*/
1212
interface MimePartInterface
1313
{

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Framework\Mail\EmailMessageInterface;
1616
use Magento\Framework\Mail\EmailMessageInterfaceFactory;
1717
use Magento\Framework\Mail\AddressConverter;
18+
use Magento\Framework\Mail\Exception\InvalidArgumentException;
1819
use Magento\Framework\Mail\MessageInterface;
1920
use Magento\Framework\Mail\MessageInterfaceFactory;
2021
use Magento\Framework\Mail\MimeInterface;
@@ -178,7 +179,6 @@ public function __construct(
178179
* @param string $name
179180
*
180181
* @return $this
181-
* @throws MailException
182182
*/
183183
public function addCc($address, $name = '')
184184
{
@@ -194,7 +194,7 @@ public function addCc($address, $name = '')
194194
* @param string $name
195195
*
196196
* @return $this
197-
* @throws MailException
197+
* @throws InvalidArgumentException
198198
*/
199199
public function addTo($address, $name = '')
200200
{
@@ -209,7 +209,7 @@ public function addTo($address, $name = '')
209209
* @param array|string $address
210210
*
211211
* @return $this
212-
* @throws MailException
212+
* @throws InvalidArgumentException
213213
*/
214214
public function addBcc($address)
215215
{
@@ -225,7 +225,7 @@ public function addBcc($address)
225225
* @param string|null $name
226226
*
227227
* @return $this
228-
* @throws MailException
228+
* @throws InvalidArgumentException
229229
*/
230230
public function setReplyTo($email, $name = null)
231231
{
@@ -240,7 +240,7 @@ public function setReplyTo($email, $name = null)
240240
* @param string|array $from
241241
*
242242
* @return $this
243-
* @throws MailException
243+
* @throws InvalidArgumentException
244244
* @see setFromByScope()
245245
*
246246
* @deprecated This function sets the from address but does not provide
@@ -258,6 +258,7 @@ public function setFrom($from)
258258
* @param string|int $scopeId
259259
*
260260
* @return $this
261+
* @throws InvalidArgumentException
261262
* @throws MailException
262263
*/
263264
public function setFromByScope($from, $scopeId = null)
@@ -412,7 +413,7 @@ protected function prepareMessage()
412413
* @param string|null $name
413414
*
414415
* @return void
415-
* @throws MailException
416+
* @throws InvalidArgumentException
416417
*/
417418
private function addAddressByType(string $addressType, $email, ?string $name = null): void
418419
{

lib/internal/Magento/Framework/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"zendframework/zend-uri": "^2.5.1",
3939
"zendframework/zend-validator": "^2.6.0",
4040
"zendframework/zend-mail": "^2.9.0",
41+
"zendframework/zend-mime": "^2.5.0",
4142
"guzzlehttp/guzzle": "^6.3.3"
4243
},
4344
"archive": {

0 commit comments

Comments
 (0)