Skip to content

Commit

Permalink
Simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jan 4, 2025
1 parent 29c39e6 commit 1017fe9
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ public function fromStrings(#[\SensitiveParameter] array $dsns): Transports
public function fromString(#[\SensitiveParameter] string $dsn): TransportInterface
{
[$transport, $offset] = $this->parseDsn($dsn);
$dnsWithoutMainOptions = preg_replace('/[?&]retry_period=\d+/', '', $dsn);
if ($offset !== \strlen($dnsWithoutMainOptions)) {
if ($offset !== \strlen($dsn)) {
throw new InvalidArgumentException('The mailer DSN has some garbage at the end.');
}

Expand All @@ -122,10 +121,6 @@ private function parseDsn(#[\SensitiveParameter] string $dsn, int $offset = 0):
'roundrobin' => RoundRobinTransport::class,
];

$parsedUrl = parse_url($dsn);
parse_str($parsedUrl['query'] ?? '', $query);
$retryPeriod = min((int) ($query['retry_period'] ?? 60), 60);

while (true) {
foreach ($keywords as $name => $class) {
$name .= '(';
Expand All @@ -150,7 +145,12 @@ private function parseDsn(#[\SensitiveParameter] string $dsn, int $offset = 0):
}
}

return [new $class($args, $retryPeriod), $offset];
parse_str(substr($dsn, $offset + 1), $query);
if ($period = $query['retry_period'] ?? 0) {
return [new $class($args, (int) $period), $offset + \strlen('retry_period='.$period) + 1];
}

return [new $class($args), $offset];
}
}

Expand Down

0 comments on commit 1017fe9

Please sign in to comment.