Skip to content

Commit 8a50af0

Browse files
committed
MessageBuilder exceptions
1 parent 5627a03 commit 8a50af0

11 files changed

+80
-43
lines changed

resources/translations/messages.en.xlf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@
6363
<source><![CDATA[<p>Password Reset Request!</p>
6464
<p>Hello! A password reset has been requested for your account.</p>
6565
<p>Please use the following token to reset your password:</p>
66-
<p><a href="%confirmationLink%">Reset Password</a></p>
66+
<p><a href="%confirmation_link%">Reset Password</a></p>
6767
<p>If you did not request this password reset, please ignore this email.</p>
6868
<p>Thank you.</p>]]></source>
6969
<target>
7070
<![CDATA[
7171
<p>Password Reset Request!</p>
7272
<p>Hello! A password reset has been requested for your account.</p>
7373
<p>Please use the following token to reset your password:</p>
74-
<p><a href="%confirmationLink%">Reset Password</a></p>
74+
<p><a href="%confirmation_link%">Reset Password</a></p>
7575
<p>If you did not request this password reset, please ignore this email.</p>
7676
<p>Thank you.</p>
7777
]]>
@@ -88,15 +88,15 @@
8888

8989
Please confirm your subscription by clicking the link below:
9090

91-
%confirmationLink%
91+
%confirmation_link%
9292

9393
If you did not request this subscription, please ignore this email.
9494
</source>
9595
<target>Thank you for subscribing!
9696

9797
Please confirm your subscription by clicking the link below:
9898

99-
%confirmationLink%
99+
%confirmation_link%
100100

101101
If you did not request this subscription, please ignore this email.
102102
</target>
@@ -105,12 +105,12 @@
105105
<trans-unit id="identity.subscription_confirmation.html">
106106
<source><![CDATA[<p>Thank you for subscribing!</p>
107107
<p>Please confirm your subscription by clicking the link below:</p>
108-
<p><a href="%confirmationLink%">Confirm Subscription</a></p>
108+
<p><a href="%confirmation_link%">Confirm Subscription</a></p>
109109
<p>If you did not request this subscription, please ignore this email.</p>]]>
110110
</source>
111111
<target><![CDATA[<p>Thank you for subscribing!</p>
112112
<p>Please confirm your subscription by clicking the link below:</p>
113-
<p><a href="%confirmationLink%">Confirm Subscription</a></p>
113+
<p><a href="%confirmation_link%">Confirm Subscription</a></p>
114114
<p>If you did not request this subscription, please ignore this email.</p>]]>
115115
</target>
116116
</trans-unit>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpList\Core\Domain\Messaging\Exception;
6+
7+
use LogicException;
8+
9+
class InvalidContextTypeException extends LogicException
10+
{
11+
public function __construct(string $type)
12+
{
13+
parent::__construct("Invalid context type: $type");
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpList\Core\Domain\Messaging\Exception;
6+
7+
use LogicException;
8+
9+
class InvalidDtoTypeException extends LogicException
10+
{
11+
public function __construct(string $type)
12+
{
13+
parent::__construct("Invalid dto type: $type");
14+
}
15+
}

src/Domain/Messaging/MessageHandler/PasswordResetMessageHandler.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,12 @@ public function __invoke(PasswordResetMessage $message): void
5353
<p>Password Reset Request!</p>
5454
<p>Hello! A password reset has been requested for your account.</p>
5555
<p>Please use the following token to reset your password:</p>
56-
<p><a href="%confirmationLink%">Reset Password</a></p>
56+
<p><a href="%confirmation_link%">Reset Password</a></p>
5757
<p>If you did not request this password reset, please ignore this email.</p>
5858
<p>Thank you.</p>
5959
HTML,
6060
[
61-
'%token%' => $message->getToken(),
62-
'%confirmationLink%' => $confirmationLink,
61+
'%confirmation_link%' => $confirmationLink,
6362
]
6463
);
6564

src/Domain/Messaging/MessageHandler/SubscriberConfirmationMessageHandler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public function __invoke(SubscriberConfirmationMessage $message): void
4242
4343
Please confirm your subscription by clicking the link below:
4444
45-
%confirmationLink%
45+
%confirmation_link%
4646
4747
If you did not request this subscription, please ignore this email.
4848
TXT,
4949
[
50-
'%confirmationLink%' => $confirmationLink
50+
'%confirmation_link%' => $confirmationLink
5151
]
5252
);
5353

@@ -57,11 +57,11 @@ public function __invoke(SubscriberConfirmationMessage $message): void
5757
<<<HTML
5858
<p>Thank you for subscribing!</p>
5959
<p>Please confirm your subscription by clicking the link below:</p>
60-
<p><a href="%confirmationLink%">Confirm Subscription</a></p>
60+
<p><a href="%confirmation_link%">Confirm Subscription</a></p>
6161
<p>If you did not request this subscription, please ignore this email.</p>
6262
HTML,
6363
[
64-
'%confirmationLink%' => $confirmationLink,
64+
'%confirmation_link%' => $confirmationLink,
6565
]
6666
);
6767
}

src/Domain/Messaging/Service/Builder/MessageBuilder.php

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

55
namespace PhpList\Core\Domain\Messaging\Service\Builder;
66

7-
use InvalidArgumentException;
7+
use PhpList\Core\Domain\Messaging\Exception\InvalidContextTypeException;
88
use PhpList\Core\Domain\Messaging\Model\Dto\MessageContext;
99
use PhpList\Core\Domain\Messaging\Model\Dto\MessageDtoInterface;
1010
use PhpList\Core\Domain\Messaging\Model\Message;
@@ -24,7 +24,7 @@ public function __construct(
2424
public function build(MessageDtoInterface $createMessageDto, object $context = null): Message
2525
{
2626
if (!$context instanceof MessageContext) {
27-
throw new InvalidArgumentException('Invalid context type');
27+
throw new InvalidContextTypeException(get_debug_type($context));
2828
}
2929

3030
$format = $this->messageFormatBuilder->build($createMessageDto->getFormat());
@@ -47,6 +47,14 @@ public function build(MessageDtoInterface $createMessageDto, object $context = n
4747

4848
$metadata = new Message\MessageMetadata(Message\MessageStatus::Draft);
4949

50-
return new Message($format, $schedule, $metadata, $content, $options, $context->getOwner(), $template);
50+
return new Message(
51+
format: $format,
52+
schedule: $schedule,
53+
metadata: $metadata,
54+
content: $content,
55+
options: $options,
56+
owner: $context->getOwner(),
57+
template: $template
58+
);
5159
}
5260
}

src/Domain/Messaging/Service/Builder/MessageContentBuilder.php

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

55
namespace PhpList\Core\Domain\Messaging\Service\Builder;
66

7-
use InvalidArgumentException;
7+
use PhpList\Core\Domain\Messaging\Exception\InvalidDtoTypeException;
88
use PhpList\Core\Domain\Messaging\Model\Dto\Message\MessageContentDto;
99
use PhpList\Core\Domain\Messaging\Model\Message\MessageContent;
1010

@@ -13,14 +13,14 @@ class MessageContentBuilder
1313
public function build(object $dto): MessageContent
1414
{
1515
if (!$dto instanceof MessageContentDto) {
16-
throw new InvalidArgumentException('Invalid request dto type: ' . get_class($dto));
16+
throw new InvalidDtoTypeException(get_debug_type($dto));
1717
}
1818

1919
return new MessageContent(
20-
$dto->subject,
21-
$dto->text,
22-
$dto->textMessage,
23-
$dto->footer
20+
subject: $dto->subject,
21+
text: $dto->text,
22+
textMessage: $dto->textMessage,
23+
footer: $dto->footer
2424
);
2525
}
2626
}

src/Domain/Messaging/Service/Builder/MessageFormatBuilder.php

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

55
namespace PhpList\Core\Domain\Messaging\Service\Builder;
66

7-
use InvalidArgumentException;
7+
use PhpList\Core\Domain\Messaging\Exception\InvalidDtoTypeException;
88
use PhpList\Core\Domain\Messaging\Model\Dto\Message\MessageFormatDto;
99
use PhpList\Core\Domain\Messaging\Model\Message\MessageFormat;
1010

@@ -13,13 +13,13 @@ class MessageFormatBuilder
1313
public function build(object $dto): MessageFormat
1414
{
1515
if (!$dto instanceof MessageFormatDto) {
16-
throw new InvalidArgumentException('Invalid request dto type: ' . get_class($dto));
16+
throw new InvalidDtoTypeException(get_debug_type($dto));
1717
}
1818

1919
return new MessageFormat(
20-
$dto->htmlFormated,
21-
$dto->sendFormat,
22-
$dto->formatOptions
20+
htmlFormatted: $dto->htmlFormated,
21+
sendFormat: $dto->sendFormat,
22+
formatOptions: $dto->formatOptions
2323
);
2424
}
2525
}

src/Domain/Messaging/Service/Builder/MessageOptionsBuilder.php

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

55
namespace PhpList\Core\Domain\Messaging\Service\Builder;
66

7-
use InvalidArgumentException;
7+
use PhpList\Core\Domain\Messaging\Exception\InvalidDtoTypeException;
88
use PhpList\Core\Domain\Messaging\Model\Dto\Message\MessageOptionsDto;
99
use PhpList\Core\Domain\Messaging\Model\Message\MessageOptions;
1010

@@ -13,15 +13,15 @@ class MessageOptionsBuilder
1313
public function build(object $dto): MessageOptions
1414
{
1515
if (!$dto instanceof MessageOptionsDto) {
16-
throw new InvalidArgumentException('Invalid request dto type: ' . get_class($dto));
16+
throw new InvalidDtoTypeException(get_debug_type($dto));
1717
}
1818

1919
return new MessageOptions(
20-
$dto->fromField ?? '',
21-
$dto->toField ?? '',
22-
$dto->replyTo ?? '',
23-
$dto->userSelection,
24-
null,
20+
fromField: $dto->fromField ?? '',
21+
toField: $dto->toField ?? '',
22+
replyTo: $dto->replyTo ?? '',
23+
userSelection: $dto->userSelection,
24+
rssTemplate: null,
2525
);
2626
}
2727
}

src/Domain/Messaging/Service/Builder/MessageScheduleBuilder.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace PhpList\Core\Domain\Messaging\Service\Builder;
66

77
use DateTime;
8-
use InvalidArgumentException;
8+
use PhpList\Core\Domain\Messaging\Exception\InvalidDtoTypeException;
99
use PhpList\Core\Domain\Messaging\Model\Dto\Message\MessageScheduleDto;
1010
use PhpList\Core\Domain\Messaging\Model\Message\MessageSchedule;
1111

@@ -14,15 +14,15 @@ class MessageScheduleBuilder
1414
public function build(object $dto): MessageSchedule
1515
{
1616
if (!$dto instanceof MessageScheduleDto) {
17-
throw new InvalidArgumentException('Invalid request dto type: ' . get_class($dto));
17+
throw new InvalidDtoTypeException(get_debug_type($dto));
1818
}
1919

2020
return new MessageSchedule(
21-
$dto->repeatInterval,
22-
new DateTime($dto->repeatUntil),
23-
$dto->requeueInterval,
24-
new DateTime($dto->requeueUntil),
25-
new DateTime($dto->embargo)
21+
repeatInterval: $dto->repeatInterval,
22+
repeatUntil: new DateTime($dto->repeatUntil),
23+
requeueInterval: $dto->requeueInterval,
24+
requeueUntil: new DateTime($dto->requeueUntil),
25+
embargo: new DateTime($dto->embargo)
2626
);
2727
}
2828
}

0 commit comments

Comments
 (0)