From d9c53b1c2de6d14080659b879f0fdab8b51131c2 Mon Sep 17 00:00:00 2001 From: zds <49744633+zds-s@users.noreply.github.com> Date: Fri, 26 Jul 2024 20:51:09 +0800 Subject: [PATCH] Optimized `MailManager::createSmtpTransport` (#694) * Update MailManager.php * Revert "Update MailManager.php" This reverts commit 1a9f6c9c6215a61d3136bd026879e9b5959e38fa. * feat: Refactor MailManager.php to improve readability and maintainability The code changes in `MailManager.php` refactor the `createSmtpTransport` method to improve readability and maintainability. The changes include type casting for certain configuration values and use of the null coalescing operator to handle missing values. This ensures that the method creates the SMTP transport correctly. Note: This message has been generated based on the provided code changes and recent commits. --------- Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com> --- src/MailManager.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/MailManager.php b/src/MailManager.php index 5ff9e5e..5ac21e3 100644 --- a/src/MailManager.php +++ b/src/MailManager.php @@ -203,7 +203,6 @@ protected function resolve(string $name): Mailer protected function createSmtpTransport(array $config): EsmtpTransport { $factory = new EsmtpTransportFactory(); - $scheme = $config['scheme'] ?? null; if (! $scheme) { @@ -215,10 +214,10 @@ protected function createSmtpTransport(array $config): EsmtpTransport /** @var EsmtpTransport $transport */ $transport = $factory->create(new Dsn( $scheme, - $config['host'], - $config['username'] ?? null, - $config['password'] ?? null, - $config['port'] ?? null, + (string) $config['host'], + isset($config['username']) ? ((string) $config['username']) : null, + isset($config['password']) ? ((string) $config['password']) : null, + isset($config['port']) ? ((int) $config['port']) : null, $config ));