From bd8b1786c56a6cbff0cc84308e96b856dff5f335 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 15 Feb 2021 10:00:35 +0100 Subject: [PATCH] Some psalm fixes in the settings app Signed-off-by: Roeland Jago Douma --- apps/settings/lib/Controller/HelpController.php | 2 +- apps/settings/lib/Mailer/NewUserMailHelper.php | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/settings/lib/Controller/HelpController.php b/apps/settings/lib/Controller/HelpController.php index 93c3bee193..b612303f9f 100644 --- a/apps/settings/lib/Controller/HelpController.php +++ b/apps/settings/lib/Controller/HelpController.php @@ -73,7 +73,7 @@ class HelpController extends Controller { public function help(string $mode = 'user'): TemplateResponse { $this->navigationManager->setActiveEntry('help'); - if (!isset($mode) || $mode !== 'admin') { + if ($mode !== 'admin') { $mode = 'user'; } diff --git a/apps/settings/lib/Mailer/NewUserMailHelper.php b/apps/settings/lib/Mailer/NewUserMailHelper.php index f8dfeec30f..abee7b2e04 100644 --- a/apps/settings/lib/Mailer/NewUserMailHelper.php +++ b/apps/settings/lib/Mailer/NewUserMailHelper.php @@ -172,9 +172,16 @@ class NewUserMailHelper { * @throws \Exception If mail could not be sent */ public function sendMail(IUser $user, - IEMailTemplate $emailTemplate) { + IEMailTemplate $emailTemplate): void { + + // Be sure to never try to send to an empty e-mail + $email = $user->getEMailAddress(); + if ($email === null) { + return; + } + $message = $this->mailer->createMessage(); - $message->setTo([$user->getEMailAddress() => $user->getDisplayName()]); + $message->setTo([$email => $user->getDisplayName()]); $message->setFrom([$this->fromAddress => $this->themingDefaults->getName()]); $message->useTemplate($emailTemplate); $this->mailer->send($message);