Skip to content

Commit fd51731

Browse files
TatevikGrtatevikg1
andauthored
Exceptions + translations (#361)
* MissingMessageIdException * MailboxConnectionException * BadMethodCallException (style fix) * Translate user facing messages * Translate * Translate PasswordResetMessageHandler texts * Translate SubscriberConfirmationMessageHandler texts * MessageBuilder exceptions * BlacklistEmailAndDeleteBounceHandler * BlacklistEmailHandler - AdvancedBounceRulesProcessor * AdvancedBounceRulesProcessor * BounceStatus * CampaignProcessor * UnidentifiedBounceReprocessor * Style fix * Test fix * ConsecutiveBounceHandler --------- Co-authored-by: Tatevik <[email protected]>
1 parent fa42258 commit fd51731

File tree

103 files changed

+1305
-397
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1305
-397
lines changed

resources/translations/messages.en.xlf

Lines changed: 447 additions & 41 deletions
Large diffs are not rendered by default.
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\Analytics\Exception;
6+
7+
use LogicException;
8+
9+
class MissingMessageIdException extends LogicException
10+
{
11+
public function __construct()
12+
{
13+
parent::__construct('Message must have an ID');
14+
}
15+
}

src/Domain/Analytics/Service/LinkTrackService.php

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

55
namespace PhpList\Core\Domain\Analytics\Service;
66

7-
use InvalidArgumentException;
87
use PhpList\Core\Core\ConfigProvider;
8+
use PhpList\Core\Domain\Analytics\Exception\MissingMessageIdException;
99
use PhpList\Core\Domain\Analytics\Model\LinkTrack;
1010
use PhpList\Core\Domain\Analytics\Repository\LinkTrackRepository;
1111
use PhpList\Core\Domain\Messaging\Model\Message;
@@ -36,7 +36,7 @@ public function isExtractAndSaveLinksApplicable(): bool
3636
* Extract links from message content and save them to the LinkTrackRepository
3737
*
3838
* @return LinkTrack[] The saved LinkTrack entities
39-
* @throws InvalidArgumentException if the message doesn't have an ID
39+
* @throws MissingMessageIdException
4040
*/
4141
public function extractAndSaveLinks(Message $message, int $userId): array
4242
{
@@ -48,7 +48,7 @@ public function extractAndSaveLinks(Message $message, int $userId): array
4848
$messageId = $message->getId();
4949

5050
if ($messageId === null) {
51-
throw new InvalidArgumentException('Message must have an ID');
51+
throw new MissingMessageIdException();
5252
}
5353

5454
$links = $this->extractLinksFromHtml($content->getText() ?? '');
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpList\Core\Domain\Common\Exception;
6+
7+
use RuntimeException;
8+
use Throwable;
9+
10+
class MailboxConnectionException extends RuntimeException
11+
{
12+
public function __construct(string $mailbox, ?string $message = null, ?Throwable $previous = null)
13+
{
14+
if ($message === null) {
15+
$message = sprintf(
16+
'Cannot open mailbox "%s": %s',
17+
$mailbox,
18+
imap_last_error() ?: 'unknown error'
19+
);
20+
}
21+
parent::__construct($message, 0, $previous);
22+
}
23+
}

src/Domain/Common/I18n/Messages.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/Domain/Common/IspRestrictionsProvider.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ private function readConfigFile(): ?string
3737
$contents = file_get_contents($this->confPath);
3838
if ($contents === false) {
3939
$this->logger->warning('Cannot read ISP restrictions file', ['path' => $this->confPath]);
40+
4041
return null;
4142
}
43+
4244
return $contents;
4345
}
4446

@@ -106,20 +108,24 @@ private function applyKeyValue(
106108
if ($val !== '' && ctype_digit($val)) {
107109
$maxBatch = (int) $val;
108110
}
111+
109112
return [$maxBatch, $minBatchPeriod, $lockFile];
110113
}
111114
if ($key === 'minbatchperiod') {
112115
if ($val !== '' && ctype_digit($val)) {
113116
$minBatchPeriod = (int) $val;
114117
}
118+
115119
return [$maxBatch, $minBatchPeriod, $lockFile];
116120
}
117121
if ($key === 'lockfile') {
118122
if ($val !== '') {
119123
$lockFile = $val;
120124
}
125+
121126
return [$maxBatch, $minBatchPeriod, $lockFile];
122127
}
128+
123129
return [$maxBatch, $minBatchPeriod, $lockFile];
124130
}
125131

src/Domain/Common/Mail/NativeImapMailReader.php

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

77
use DateTimeImmutable;
88
use IMAP\Connection;
9-
use RuntimeException;
9+
use PhpList\Core\Domain\Common\Exception\MailboxConnectionException;
1010

1111
class NativeImapMailReader
1212
{
@@ -24,7 +24,7 @@ public function open(string $mailbox, int $options = 0): Connection
2424
$link = imap_open($mailbox, $this->username, $this->password, $options);
2525

2626
if ($link === false) {
27-
throw new RuntimeException('Cannot open mailbox: '.(imap_last_error() ?: 'unknown error'));
27+
throw new MailboxConnectionException($mailbox);
2828
}
2929

3030
return $link;

src/Domain/Common/Repository/CursorPaginationTrait.php

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

55
namespace PhpList\Core\Domain\Common\Repository;
66

7+
use BadMethodCallException;
78
use PhpList\Core\Domain\Common\Model\Filter\FilterRequestInterface;
89
use PhpList\Core\Domain\Common\Model\Interfaces\DomainModel;
9-
use RuntimeException;
1010

1111
trait CursorPaginationTrait
1212
{
@@ -30,14 +30,14 @@ public function getAfterId(int $lastId, int $limit): array
3030
* Get filtered + paginated messages for a given owner and status.
3131
*
3232
* @return DomainModel[]
33-
* @throws RuntimeException
34-
*/
33+
* @throws BadMethodCallException
34+
* */
3535
public function getFilteredAfterId(int $lastId, int $limit, ?FilterRequestInterface $filter = null): array
3636
{
3737
if ($filter === null) {
3838
return $this->getAfterId($lastId, $limit);
3939
}
4040

41-
throw new RuntimeException('Filter method not implemented');
41+
throw new BadMethodCallException('getFilteredAfterId method not implemented');
4242
}
4343
}

src/Domain/Common/SystemInfoCollector.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ class SystemInfoCollector
1616
/**
1717
* @param string[] $configuredKeys keys to include (empty => use defaults)
1818
*/
19-
public function __construct(
20-
RequestStack $requestStack,
21-
array $configuredKeys = []
22-
) {
19+
public function __construct(RequestStack $requestStack, array $configuredKeys = [])
20+
{
2321
$this->requestStack = $requestStack;
2422
$this->configuredKeys = $configuredKeys;
2523
}
@@ -72,6 +70,7 @@ public function collectAsString(): string
7270
foreach ($pairs as $k => $v) {
7371
$lines[] = sprintf('%s = %s', $k, $v);
7472
}
73+
7574
return "\n" . implode("\n", $lines);
7675
}
7776
}

src/Domain/Configuration/Service/Manager/EventLogManager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function get(
4444
?DateTimeInterface $dateTo = null
4545
): array {
4646
$filter = new EventLogFilter($page, $dateFrom, $dateTo);
47+
4748
return $this->repository->getFilteredAfterId($lastId, $limit, $filter);
4849
}
4950

0 commit comments

Comments
 (0)