Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Clean up code.
James Cole5f1502eea78c
diff --git a/app/Notifications/Admin/UnknownUserLoginAttempt.php b/app/Notifications/Admin/UnknownUserLoginAttempt.phpindex 6ee20a56e9..e4eb4a678b 100644--- a/app/Notifications/Admin/UnknownUserLoginAttempt.php+++ b/app/Notifications/Admin/UnknownUserLoginAttempt.php@@ -37,6 +37,7 @@ use Ntfy\Message;class UnknownUserLoginAttempt extends Notification{use Queueable;+private string $address;public function __construct(string $address)@@ -60,18 +61,21 @@ class UnknownUserLoginAttempt extends Notification{return new MailMessage()->markdown('emails.owner.unknown-user', ['address' => $this->address])- ->subject((string) trans('email.unknown_user_subject'))- ;+ ->subject((string) trans('email.unknown_user_subject'));}/*** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/- public function toSlack(OwnerNotifiable $notifiable): SlackMessage+ public function toNtfy(OwnerNotifiable $notifiable): Message{- return new SlackMessage()->content(- (string) trans('email.unknown_user_body', ['address' => $this->address])- );+ $settings = ReturnsSettings::getSettings('ntfy', 'owner', null);+ $message = new Message();+ $message->topic($settings['ntfy_topic']);+ $message->title((string) trans('email.unknown_user_subject'));+ $message->body((string) trans('email.unknown_user_message', ['address' => $this->address]));++ return $message;}/**@@ -80,22 +84,17 @@ class UnknownUserLoginAttempt extends Notificationpublic function toPushover(OwnerNotifiable $notifiable): PushoverMessage{return PushoverMessage::create((string) trans('email.unknown_user_message', ['address' => $this->address]))- ->title((string) trans('email.unknown_user_subject'))- ;+ ->title((string) trans('email.unknown_user_subject'));}/*** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/- public function toNtfy(OwnerNotifiable $notifiable): Message+ public function toSlack(OwnerNotifiable $notifiable): SlackMessage{- $settings = ReturnsSettings::getSettings('ntfy', 'owner', null);- $message = new Message();- $message->topic($settings['ntfy_topic']);- $message->title((string) trans('email.unknown_user_subject'));- $message->body((string) trans('email.unknown_user_message', ['address' => $this->address]));-- return $message;+ return new SlackMessage()->content(+ (string) trans('email.unknown_user_body', ['address' => $this->address])+ );}/**diff --git a/app/Notifications/Admin/UserInvitation.php b/app/Notifications/Admin/UserInvitation.phpindex a9d40ab9b0..8ac48334aa 100644--- a/app/Notifications/Admin/UserInvitation.php+++ b/app/Notifications/Admin/UserInvitation.php@@ -69,19 +69,24 @@ class UserInvitation extends Notification{return (new MailMessage())->markdown('emails.invitation-created', ['email' => $this->invitee->user->email, 'invitee' => $this->invitee->email])- ->subject((string) trans('email.invitation_created_subject'))- ;+ ->subject((string) trans('email.invitation_created_subject'));}/*** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/- public function toSlack(OwnerNotifiable $notifiable)+ public function toNtfy(OwnerNotifiable $notifiable): Message{- return (new SlackMessage())->content(- (string) trans('email.invitation_created_body', ['email' => $this->invitee->user->email, 'invitee' => $this->invitee->email])- );+ Log::debug('Now in toNtfy() for UserInvitation');+ $settings = ReturnsSettings::getSettings('ntfy', 'owner', null);+ $message = new Message();+ $message->topic($settings['ntfy_topic']);+ $message->title((string) trans('email.invitation_created_subject'));+ $message->body((string) trans('email.invitation_created_body', ['email' => $this->invitee->user->email, 'invitee' => $this->invitee->email]));++ return $message;}+/*** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/@@ -90,22 +95,17 @@ class UserInvitation extends NotificationLog::debug('Now in toPushover() for UserInvitation');return PushoverMessage::create((string) trans('email.invitation_created_body', ['email' => $this->invitee->user->email, 'invitee' => $this->invitee->email]))- ->title((string) trans('email.invitation_created_subject'))- ;+ ->title((string) trans('email.invitation_created_subject'));}+/*** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/- public function toNtfy(OwnerNotifiable $notifiable): Message+ public function toSlack(OwnerNotifiable $notifiable){- Log::debug('Now in toNtfy() for UserInvitation');- $settings = ReturnsSettings::getSettings('ntfy', 'owner', null);- $message = new Message();- $message->topic($settings['ntfy_topic']);- $message->title((string) trans('email.invitation_created_subject'));- $message->body((string) trans('email.invitation_created_body', ['email' => $this->invitee->user->email, 'invitee' => $this->invitee->email]));-- return $message;+ return (new SlackMessage())->content(+ (string) trans('email.invitation_created_body', ['email' => $this->invitee->user->email, 'invitee' => $this->invitee->email])+ );}/**diff --git a/app/Notifications/Admin/UserRegistration.php b/app/Notifications/Admin/UserRegistration.phpindex e28e1ca239..90af37ff63 100644--- a/app/Notifications/Admin/UserRegistration.php+++ b/app/Notifications/Admin/UserRegistration.php@@ -69,17 +69,24 @@ class UserRegistration extends Notification{return (new MailMessage())->markdown('emails.registered-admin', ['email' => $this->user->email, 'id' => $this->user->id])- ->subject((string) trans('email.registered_subject_admin'))- ;+ ->subject((string) trans('email.registered_subject_admin'));}/*** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/- public function toSlack(OwnerNotifiable $notifiable)+ public function toNtfy(OwnerNotifiable $notifiable): Message{- return (new SlackMessage())->content((string) trans('email.admin_new_user_registered', ['email' => $this->user->email, 'id' => $this->user->id]));+ Log::debug('Now in toNtfy() for (Admin) UserRegistration');+ $settings = ReturnsSettings::getSettings('ntfy', 'owner', null);+ $message = new Message();+ $message->topic($settings['ntfy_topic']);+ $message->title((string) trans('email.registered_subject_admin'));+ $message->body((string) trans('email.admin_new_user_registered', ['email' => $this->user->email, 'invitee' => $this->user->email]));++ return $message;}+/*** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/@@ -88,22 +95,15 @@ class UserRegistration extends NotificationLog::debug('Now in toPushover() for UserRegistration');return PushoverMessage::create((string) trans('email.admin_new_user_registered', ['email' => $this->user->email, 'invitee' => $this->user->email]))- ->title((string) trans('email.registered_subject_admin'))- ;+ ->title((string) trans('email.registered_subject_admin'));}+/*** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/- public function toNtfy(OwnerNotifiable $notifiable): Message+ public function toSlack(OwnerNotifiable $notifiable){- Log::debug('Now in toNtfy() for (Admin) UserRegistration');- $settings = ReturnsSettings::getSettings('ntfy', 'owner', null);- $message = new Message();- $message->topic($settings['ntfy_topic']);- $message->title((string) trans('email.registered_subject_admin'));- $message->body((string) trans('email.admin_new_user_registered', ['email' => $this->user->email, 'invitee' => $this->user->email]));-- return $message;+ return (new SlackMessage())->content((string) trans('email.admin_new_user_registered', ['email' => $this->user->email, 'id' => $this->user->id]));}/**diff --git a/app/Notifications/Admin/VersionCheckResult.php b/app/Notifications/Admin/VersionCheckResult.phpindex 68e28475d9..d809913e74 100644--- a/app/Notifications/Admin/VersionCheckResult.php+++ b/app/Notifications/Admin/VersionCheckResult.php@@ -66,21 +66,24 @@ class VersionCheckResult extends Notification{return (new MailMessage())->markdown('emails.new-version', ['message' => $this->message])- ->subject((string)trans('email.new_version_email_subject'))- ;+ ->subject((string) trans('email.new_version_email_subject'));}/*** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/- public function toSlack(OwnerNotifiable $notifiable)+ public function toNtfy(OwnerNotifiable $notifiable): Message{- return (new SlackMessage())->content($this->message)- ->attachment(static function ($attachment): void {- $attachment->title('Firefly III @ GitHub', 'https://github.com/firefly-iii/firefly-iii/releases');- })- ;+ Log::debug('Now in toNtfy() for VersionCheckResult');+ $settings = ReturnsSettings::getSettings('ntfy', 'owner', null);+ $message = new Message();+ $message->topic($settings['ntfy_topic']);+ $message->title((string) trans('email.new_version_email_subject'));+ $message->body($this->message);++ return $message;}+/*** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/@@ -89,22 +92,18 @@ class VersionCheckResult extends NotificationLog::debug('Now in toPushover() for VersionCheckResult');return PushoverMessage::create($this->message)- ->title((string) trans('email.new_version_email_subject'))- ;+ ->title((string) trans('email.new_version_email_subject'));}+/*** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/- public function toNtfy(OwnerNotifiable $notifiable): Message+ public function toSlack(OwnerNotifiable $notifiable){- Log::debug('Now in toNtfy() for VersionCheckResult');- $settings = ReturnsSettings::getSettings('ntfy', 'owner', null);- $message = new Message();- $message->topic($settings['ntfy_topic']);- $message->title((string) trans('email.new_version_email_subject'));- $message->body($this->message);-- return $message;+ return (new SlackMessage())->content($this->message)+ ->attachment(static function ($attachment): void {+ $attachment->title('Firefly III @ GitHub', 'https://github.com/firefly-iii/firefly-iii/releases');+ });}/**diff --git a/app/Notifications/Notifiables/OwnerNotifiable.php b/app/Notifications/Notifiables/OwnerNotifiable.phpindex 4fc165487d..47abd5e0fd 100644--- a/app/Notifications/Notifiables/OwnerNotifiable.php+++ b/app/Notifications/Notifiables/OwnerNotifiable.php@@ -31,27 +31,6 @@ use NotificationChannels\Pushover\PushoverReceiver;class OwnerNotifiable{- public function routeNotificationForSlack(): string- {- $res = app('fireflyconfig')->getEncrypted('slack_webhook_url', '')->data;- if (is_array($res)) {- $res = '';- }-- return (string) $res;- }-- public function routeNotificationForPushover()- {- Log::debug('Return settings for routeNotificationForPushover');- $pushoverAppToken = (string) app('fireflyconfig')->getEncrypted('pushover_app_token', '')->data;- $pushoverUserToken = (string) app('fireflyconfig')->getEncrypted('pushover_user_token', '')->data;-- return PushoverReceiver::withUserKey($pushoverUserToken)- ->withApplicationToken($pushoverAppToken)- ;- }-/*** Get the notification routing information for the given driver.*@@ -62,7 +41,7 @@ class OwnerNotifiable*/public function routeNotificationFor($driver, $notification = null){- $method = 'routeNotificationFor'.Str::studly($driver);+ $method = 'routeNotificationFor' . Str::studly($driver);if (method_exists($this, $method)) {Log::debug(sprintf('Redirect for settings to "%s".', $method));@@ -75,4 +54,24 @@ class OwnerNotifiabledefault => null,};}++ public function routeNotificationForPushover()+ {+ Log::debug('Return settings for routeNotificationForPushover');+ $pushoverAppToken = (string) app('fireflyconfig')->getEncrypted('pushover_app_token', '')->data;+ $pushoverUserToken = (string) app('fireflyconfig')->getEncrypted('pushover_user_token', '')->data;++ return PushoverReceiver::withUserKey($pushoverUserToken)+ ->withApplicationToken($pushoverAppToken);+ }++ public function routeNotificationForSlack(): string+ {+ $res = app('fireflyconfig')->getEncrypted('slack_webhook_url', '')->data;+ if (is_array($res)) {+ $res = '';+ }++ return (string) $res;+ }}diff --git a/app/Notifications/ReturnsAvailableChannels.php b/app/Notifications/ReturnsAvailableChannels.phpindex 56e6de1b0e..0e35e1bd64 100644--- a/app/Notifications/ReturnsAvailableChannels.php+++ b/app/Notifications/ReturnsAvailableChannels.php@@ -39,7 +39,7 @@ class ReturnsAvailableChannelsif ('owner' === $type) {return self::returnOwnerChannels();}- if('user' === $type && null !== $user) {+ if ('user' === $type && null !== $user) {return self::returnUserChannels($user);}@@ -50,8 +50,8 @@ class ReturnsAvailableChannelsprivate static function returnOwnerChannels(): array{- $channels = ['mail'];- $slackUrl = app('fireflyconfig')->getEncrypted('slack_webhook_url', '')->data;+ $channels = ['mail'];+ $slackUrl = app('fireflyconfig')->getEncrypted('slack_webhook_url', '')->data;if (UrlValidator::isValidWebhookURL($slackUrl)) {$channels[] = 'slack';}@@ -81,19 +81,20 @@ class ReturnsAvailableChannelsreturn $channels;}- private static function returnUserChannels(User $user): array {- $channels = ['mail'];- $slackUrl = app('preferences')->getEncryptedForUser($user, 'slack_webhook_url', '')->data;+ private static function returnUserChannels(User $user): array+ {+ $channels = ['mail'];+ $slackUrl = app('preferences')->getEncryptedForUser($user, 'slack_webhook_url', '')->data;if (UrlValidator::isValidWebhookURL($slackUrl)) {$channels[] = 'slack';}// validate presence of of Ntfy settings.- if ('' !== (string) app('preferences')->getEncryptedForUser($user,'ntfy_topic', '')->data) {+ if ('' !== (string) app('preferences')->getEncryptedForUser($user, 'ntfy_topic', '')->data) {Log::debug('Enabled ntfy.');$channels[] = NtfyChannel::class;}- if ('' === (string) app('preferences')->getEncryptedForUser($user,'ntfy_topic', '')->data) {+ if ('' === (string) app('preferences')->getEncryptedForUser($user, 'ntfy_topic', '')->data) {Log::warning('No topic name for Ntfy, channel is disabled.');}diff --git a/app/Notifications/ReturnsSettings.php b/app/Notifications/ReturnsSettings.phpindex 6dd2a365c6..f0582ec751 100644--- a/app/Notifications/ReturnsSettings.php+++ b/app/Notifications/ReturnsSettings.php@@ -50,7 +50,7 @@ class ReturnsSettings'ntfy_pass' => '',];- if('user' === $type && null !== $user) {+ if ('user' === $type && null !== $user) {$settings['ntfy_server'] = Preferences::getEncryptedForUser($user, 'ntfy_server', 'https://ntfy.sh')->data;$settings['ntfy_topic'] = Preferences::getEncryptedForUser($user, 'ntfy_topic', '')->data;$settings['ntfy_auth'] = Preferences::getForUser($user, 'ntfy_auth', false)->data;diff --git a/app/Notifications/Security/DisabledMFANotification.php b/app/Notifications/Security/DisabledMFANotification.phpindex 48dc9462a8..de2917e711 100644--- a/app/Notifications/Security/DisabledMFANotification.php+++ b/app/Notifications/Security/DisabledMFANotification.php@@ -26,7 +26,6 @@ namespace FireflyIII\Notifications\Security;use FireflyIII\Notifications\ReturnsAvailableChannels;use FireflyIII\Notifications\ReturnsSettings;-use FireflyIII\Support\Notifications\UrlValidator;use FireflyIII\User;use Illuminate\Bus\Queueable;use Illuminate\Notifications\Messages\MailMessage;@@ -46,6 +45,7 @@ class DisabledMFANotification extends Notification{$this->user = $user;}+/*** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/@@ -64,15 +64,21 @@ class DisabledMFANotification extends Notificationreturn (new MailMessage())->markdown('emails.security.disabled-mfa', ['user' => $this->user])->subject($subject);}+/*** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/- public function toSlack(User $notifiable)+ public function toNtfy(User $user): Message{- $message = (string) trans('email.disabled_mfa_slack', ['email' => $this->user->email]);+ $settings = ReturnsSettings::getSettings('ntfy', 'user', $user);+ $message = new Message();+ $message->topic($settings['ntfy_topic']);+ $message->title((string) trans('email.disabled_mfa_subject'));+ $message->body((string) trans('email.disabled_mfa_slack', ['email' => $this->user->email]));- return (new SlackMessage())->content($message);+ return $message;}+/*** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/@@ -81,20 +87,17 @@ class DisabledMFANotification extends NotificationLog::debug('Now in (user) toPushover()');return PushoverMessage::create((string) trans('email.disabled_mfa_slack', ['email' => $this->user->email]))- ->title((string)trans('email.disabled_mfa_subject'));+ ->title((string) trans('email.disabled_mfa_subject'));}+/*** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/- public function toNtfy(User $user): Message+ public function toSlack(User $notifiable){- $settings = ReturnsSettings::getSettings('ntfy', 'user', $user);- $message = new Message();- $message->topic($settings['ntfy_topic']);- $message->title((string)trans('email.disabled_mfa_subject'));- $message->body((string) trans('email.disabled_mfa_slack', ['email' => $this->user->email]));+ $message = (string) trans('email.disabled_mfa_slack', ['email' => $this->user->email]);- return $message;+ return (new SlackMessage())->content($message);}/**diff --git a/app/Notifications/Security/EnabledMFANotification.php b/app/Notifications/Security/EnabledMFANotification.phpindex fc927be354..db6ba42652 100644--- a/app/Notifications/Security/EnabledMFANotification.php+++ b/app/Notifications/Security/EnabledMFANotification.php@@ -24,7 +24,7 @@ declare(strict_types=1);namespace FireflyIII\Notifications\Security;-use FireflyIII\Support\Notifications\UrlValidator;+use FireflyIII\Notifications\ReturnsAvailableChannels;use FireflyIII\User;use Illuminate\Bus\Queueable;use Illuminate\Notifications\Messages\MailMessage;@@ -35,7 +35,7 @@ class EnabledMFANotification extends Notification{use Queueable;- private User $user;+ private User $user;public function __construct(User $user)@@ -43,42 +43,41 @@ class EnabledMFANotification extends Notification$this->user = $user;}-- public function toArray($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toArray(User $notifiable){return [];}-- public function toMail($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toMail(User $notifiable){- $subject = (string)trans('email.enabled_mfa_subject');+ $subject = (string) trans('email.enabled_mfa_subject');return (new MailMessage())->markdown('emails.security.enabled-mfa', ['user' => $this->user])->subject($subject);}-- public function toSlack($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toSlack(User $notifiable){- $message = (string)trans('email.enabled_mfa_slack', ['email' => $this->user->email]);+ $message = (string) trans('email.enabled_mfa_slack', ['email' => $this->user->email]);return (new SlackMessage())->content($message);}- public function via($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function via(User $notifiable){- /** @var null|User $user */- $user = auth()->user();- $slackUrl = null === $user ? '' : app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;- if (is_array($slackUrl)) {- $slackUrl = '';- }- if (UrlValidator::isValidWebhookURL((string)$slackUrl)) {- return ['mail', 'slack'];- }-- return ['mail'];+ return ReturnsAvailableChannels::returnChannels('user', $notifiable);}}diff --git a/app/Notifications/Security/MFABackupFewLeftNotification.php b/app/Notifications/Security/MFABackupFewLeftNotification.phpindex c4e7209bb6..f9b1c65e8e 100644--- a/app/Notifications/Security/MFABackupFewLeftNotification.php+++ b/app/Notifications/Security/MFABackupFewLeftNotification.php@@ -24,7 +24,7 @@ declare(strict_types=1);namespace FireflyIII\Notifications\Security;-use FireflyIII\Support\Notifications\UrlValidator;+use FireflyIII\Notifications\ReturnsAvailableChannels;use FireflyIII\User;use Illuminate\Bus\Queueable;use Illuminate\Notifications\Messages\MailMessage;@@ -35,9 +35,8 @@ class MFABackupFewLeftNotification extends Notification{use Queueable;- private User $user;- private int $count;-+ private int $count;+ private User $user;public function __construct(User $user, int $count){@@ -45,42 +44,41 @@ class MFABackupFewLeftNotification extends Notification$this->count = $count;}-- public function toArray($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toArray(User $notifiable){return [];}-- public function toMail($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toMail(User $notifiable){- $subject = (string)trans('email.mfa_few_backups_left_subject', ['count' => $this->count]);+ $subject = (string) trans('email.mfa_few_backups_left_subject', ['count' => $this->count]);return (new MailMessage())->markdown('emails.security.few-backup-codes', ['user' => $this->user, 'count' => $this->count])->subject($subject);}-- public function toSlack($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toSlack(User $notifiable){- $message = (string)trans('email.mfa_few_backups_left_slack', ['email' => $this->user->email, 'count' => $this->count]);+ $message = (string) trans('email.mfa_few_backups_left_slack', ['email' => $this->user->email, 'count' => $this->count]);return (new SlackMessage())->content($message);}- public function via($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function via(User $notifiable){- /** @var null|User $user */- $user = auth()->user();- $slackUrl = null === $user ? '' : app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;- if (is_array($slackUrl)) {- $slackUrl = '';- }- if (UrlValidator::isValidWebhookURL((string)$slackUrl)) {- return ['mail', 'slack'];- }-- return ['mail'];+ return ReturnsAvailableChannels::returnChannels('user', $notifiable);}}diff --git a/app/Notifications/Security/MFABackupNoLeftNotification.php b/app/Notifications/Security/MFABackupNoLeftNotification.phpindex 5e0199c079..ee53d2ecb7 100644--- a/app/Notifications/Security/MFABackupNoLeftNotification.php+++ b/app/Notifications/Security/MFABackupNoLeftNotification.php@@ -24,7 +24,7 @@ declare(strict_types=1);namespace FireflyIII\Notifications\Security;-use FireflyIII\Support\Notifications\UrlValidator;+use FireflyIII\Notifications\ReturnsAvailableChannels;use FireflyIII\User;use Illuminate\Bus\Queueable;use Illuminate\Notifications\Messages\MailMessage;@@ -35,7 +35,7 @@ class MFABackupNoLeftNotification extends Notification{use Queueable;- private User $user;+ private User $user;public function __construct(User $user)@@ -43,42 +43,41 @@ class MFABackupNoLeftNotification extends Notification$this->user = $user;}-- public function toArray($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toArray(User $notifiable){return [];}-- public function toMail($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toMail(User $notifiable){- $subject = (string)trans('email.mfa_no_backups_left_subject');+ $subject = (string) trans('email.mfa_no_backups_left_subject');return (new MailMessage())->markdown('emails.security.no-backup-codes', ['user' => $this->user])->subject($subject);}-- public function toSlack($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toSlack(User $notifiable){- $message = (string)trans('email.mfa_no_backups_left_slack', ['email' => $this->user->email]);+ $message = (string) trans('email.mfa_no_backups_left_slack', ['email' => $this->user->email]);return (new SlackMessage())->content($message);}- public function via($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function via(User $notifiable){- /** @var null|User $user */- $user = auth()->user();- $slackUrl = null === $user ? '' : app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;- if (is_array($slackUrl)) {- $slackUrl = '';- }- if (UrlValidator::isValidWebhookURL((string)$slackUrl)) {- return ['mail', 'slack'];- }-- return ['mail'];+ return ReturnsAvailableChannels::returnChannels('user', $notifiable);}}diff --git a/app/Notifications/Security/MFAManyFailedAttemptsNotification.php b/app/Notifications/Security/MFAManyFailedAttemptsNotification.phpindex d7d78863fe..f21bc3d337 100644--- a/app/Notifications/Security/MFAManyFailedAttemptsNotification.php+++ b/app/Notifications/Security/MFAManyFailedAttemptsNotification.php@@ -24,7 +24,7 @@ declare(strict_types=1);namespace FireflyIII\Notifications\Security;-use FireflyIII\Support\Notifications\UrlValidator;+use FireflyIII\Notifications\ReturnsAvailableChannels;use FireflyIII\User;use Illuminate\Bus\Queueable;use Illuminate\Notifications\Messages\MailMessage;@@ -35,9 +35,8 @@ class MFAManyFailedAttemptsNotification extends Notification{use Queueable;- private User $user;- private int $count;-+ private int $count;+ private User $user;public function __construct(User $user, int $count){@@ -46,41 +45,38 @@ class MFAManyFailedAttemptsNotification extends Notification}- public function toArray($notifiable)+ public function toArray(User $notifiable){return [];}-- public function toMail($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toMail(User $notifiable){- $subject = (string)trans('email.mfa_many_failed_subject', ['count' => $this->count]);+ $subject = (string) trans('email.mfa_many_failed_subject', ['count' => $this->count]);return (new MailMessage())->markdown('emails.security.many-failed-attempts', ['user' => $this->user, 'count' => $this->count])->subject($subject);}-- public function toSlack($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toSlack(User $notifiable){- $message = (string)trans('email.mfa_many_failed_slack', ['email' => $this->user->email, 'count' => $this->count]);+ $message = (string) trans('email.mfa_many_failed_slack', ['email' => $this->user->email, 'count' => $this->count]);return (new SlackMessage())->content($message);}- public function via($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function via(User $notifiable){- /** @var null|User $user */- $user = auth()->user();- $slackUrl = null === $user ? '' : app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;- if (is_array($slackUrl)) {- $slackUrl = '';- }- if (UrlValidator::isValidWebhookURL((string)$slackUrl)) {- return ['mail', 'slack'];- }-- return ['mail'];+ return ReturnsAvailableChannels::returnChannels('user', $notifiable);}}diff --git a/app/Notifications/Security/MFAUsedBackupCodeNotification.php b/app/Notifications/Security/MFAUsedBackupCodeNotification.phpindex 5aac05099d..30915d8fcd 100644--- a/app/Notifications/Security/MFAUsedBackupCodeNotification.php+++ b/app/Notifications/Security/MFAUsedBackupCodeNotification.php@@ -24,7 +24,7 @@ declare(strict_types=1);namespace FireflyIII\Notifications\Security;-use FireflyIII\Support\Notifications\UrlValidator;+use FireflyIII\Notifications\ReturnsAvailableChannels;use FireflyIII\User;use Illuminate\Bus\Queueable;use Illuminate\Notifications\Messages\MailMessage;@@ -35,7 +35,7 @@ class MFAUsedBackupCodeNotification extends Notification{use Queueable;- private User $user;+ private User $user;public function __construct(User $user)@@ -43,42 +43,41 @@ class MFAUsedBackupCodeNotification extends Notification$this->user = $user;}-- public function toArray($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toArray(User $notifiable){return [];}-- public function toMail($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toMail(User $notifiable){- $subject = (string)trans('email.used_backup_code_subject');+ $subject = (string) trans('email.used_backup_code_subject');return (new MailMessage())->markdown('emails.security.used-backup-code', ['user' => $this->user])->subject($subject);}-- public function toSlack($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toSlack(User $notifiable){- $message = (string)trans('email.used_backup_code_slack', ['email' => $this->user->email]);+ $message = (string) trans('email.used_backup_code_slack', ['email' => $this->user->email]);return (new SlackMessage())->content($message);}- public function via($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function via(User $notifiable){- /** @var null|User $user */- $user = auth()->user();- $slackUrl = null === $user ? '' : app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;- if (is_array($slackUrl)) {- $slackUrl = '';- }- if (UrlValidator::isValidWebhookURL((string)$slackUrl)) {- return ['mail', 'slack'];- }-- return ['mail'];+ return ReturnsAvailableChannels::returnChannels('user', $notifiable);}}diff --git a/app/Notifications/Security/NewBackupCodesNotification.php b/app/Notifications/Security/NewBackupCodesNotification.phpindex 8973242e02..6fbe432cc2 100644--- a/app/Notifications/Security/NewBackupCodesNotification.php+++ b/app/Notifications/Security/NewBackupCodesNotification.php@@ -24,7 +24,7 @@ declare(strict_types=1);namespace FireflyIII\Notifications\Security;-use FireflyIII\Support\Notifications\UrlValidator;+use FireflyIII\Notifications\ReturnsAvailableChannels;use FireflyIII\User;use Illuminate\Bus\Queueable;use Illuminate\Notifications\Messages\MailMessage;@@ -35,7 +35,7 @@ class NewBackupCodesNotification extends Notification{use Queueable;- private User $user;+ private User $user;public function __construct(User $user)@@ -43,42 +43,40 @@ class NewBackupCodesNotification extends Notification$this->user = $user;}-- public function toArray($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toArray(User $notifiable){return [];}-- public function toMail($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toMail(User $notifiable){- $subject = (string)trans('email.new_backup_codes_subject');+ $subject = (string) trans('email.new_backup_codes_subject');return (new MailMessage())->markdown('emails.security.new-backup-codes', ['user' => $this->user])->subject($subject);}-- public function toSlack($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toSlack(User $notifiable){- $message = (string)trans('email.new_backup_codes_slack', ['email' => $this->user->email]);+ $message = (string) trans('email.new_backup_codes_slack', ['email' => $this->user->email]);return (new SlackMessage())->content($message);}-- public function via($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function via(User $notifiable){- /** @var null|User $user */- $user = auth()->user();- $slackUrl = null === $user ? '' : app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;- if (is_array($slackUrl)) {- $slackUrl = '';- }- if (UrlValidator::isValidWebhookURL((string)$slackUrl)) {- return ['mail', 'slack'];- }-- return ['mail'];+ return ReturnsAvailableChannels::returnChannels('user', $notifiable);}}diff --git a/app/Notifications/Security/UserFailedLoginAttempt.php b/app/Notifications/Security/UserFailedLoginAttempt.phpindex 51a4462dc7..90308f1aac 100644--- a/app/Notifications/Security/UserFailedLoginAttempt.php+++ b/app/Notifications/Security/UserFailedLoginAttempt.php@@ -23,7 +23,8 @@ declare(strict_types=1);namespace FireflyIII\Notifications\Security;-use FireflyIII\Support\Notifications\UrlValidator;+use FireflyIII\Notifications\ReturnsAvailableChannels;+use FireflyIII\User;use Illuminate\Bus\Queueable;use Illuminate\Notifications\Messages\MailMessage;use Illuminate\Notifications\Messages\SlackMessage;@@ -33,7 +34,7 @@ class UserFailedLoginAttempt extends Notification{use Queueable;- private User $user;+ private User $user;public function __construct(User $user)@@ -42,41 +43,37 @@ class UserFailedLoginAttempt extends Notification}- public function toArray($notifiable)+ public function toArray(User $notifiable){return [];}-- public function toMail($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toMail(User $notifiable){- $subject = (string)trans('email.new_backup_codes_subject');+ $subject = (string) trans('email.new_backup_codes_subject');return (new MailMessage())->markdown('emails.security.new-backup-codes', ['user' => $this->user])->subject($subject);}-- public function toSlack($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toSlack(User $notifiable){- $message = (string)trans('email.new_backup_codes_slack', ['email' => $this->user->email]);+ $message = (string) trans('email.new_backup_codes_slack', ['email' => $this->user->email]);return (new SlackMessage())->content($message);}-- public function via($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function via(User $notifiable){- /** @var null|User $user */- $user = auth()->user();- $slackUrl = null === $user ? '' : app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;- if (is_array($slackUrl)) {- $slackUrl = '';- }- if (UrlValidator::isValidWebhookURL((string)$slackUrl)) {- return ['mail', 'slack'];- }-- return ['mail'];+ return ReturnsAvailableChannels::returnChannels('user', $notifiable);}}diff --git a/app/Notifications/Test/OwnerTestNotificationEmail.php b/app/Notifications/Test/OwnerTestNotificationEmail.phpindex ed74b12537..60d6911a83 100644--- a/app/Notifications/Test/OwnerTestNotificationEmail.php+++ b/app/Notifications/Test/OwnerTestNotificationEmail.php@@ -45,11 +45,7 @@ class OwnerTestNotificationEmail extends Notification}/**- * Get the array representation of the notification.- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)- *- * @return array*/public function toArray(OwnerNotifiable $notifiable){@@ -58,13 +54,7 @@ class OwnerTestNotificationEmail extends Notification}/**- * Get the mail representation of the notification.- *- * @param mixed $notifiable- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)- *- * @return MailMessage*/public function toMail(OwnerNotifiable $notifiable){@@ -72,18 +62,11 @@ class OwnerTestNotificationEmail extends Notificationreturn (new MailMessage())->markdown('emails.admin-test', ['email' => $address])- ->subject((string) trans('email.admin_test_subject'))- ;+ ->subject((string) trans('email.admin_test_subject'));}/**- * Get the notification's delivery channels.- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)- *- * @param mixed $notifiable- *- * @return array*/public function via(OwnerNotifiable $notifiable){diff --git a/app/Notifications/Test/OwnerTestNotificationNtfy.php b/app/Notifications/Test/OwnerTestNotificationNtfy.phpindex d6ec326625..a343a49c5a 100644--- a/app/Notifications/Test/OwnerTestNotificationNtfy.php+++ b/app/Notifications/Test/OwnerTestNotificationNtfy.php@@ -49,13 +49,7 @@ class OwnerTestNotificationNtfy extends Notification}/**- * Get the array representation of the notification.- *- * @param mixed $notifiable- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)- *- * @return array*/public function toArray($notifiable){@@ -63,6 +57,9 @@ class OwnerTestNotificationNtfy extends Notification];}+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */public function toNtfy(OwnerNotifiable $notifiable): Message{$settings = ReturnsSettings::getSettings('ntfy', 'owner', null);diff --git a/app/Notifications/Test/OwnerTestNotificationPushover.php b/app/Notifications/Test/OwnerTestNotificationPushover.phpindex f5fdf1a032..bbb25a50b2 100644--- a/app/Notifications/Test/OwnerTestNotificationPushover.php+++ b/app/Notifications/Test/OwnerTestNotificationPushover.php@@ -49,11 +49,7 @@ class OwnerTestNotificationPushover extends Notification}/**- * Get the array representation of the notification.- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)- *- * @return array*/public function toArray(OwnerNotifiable $notifiable){@@ -61,13 +57,15 @@ class OwnerTestNotificationPushover extends Notification];}+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */public function toPushover(OwnerNotifiable $notifiable): PushoverMessage{Log::debug('Now in toPushover()');- return PushoverMessage::create((string)trans('email.admin_test_message', ['channel' => 'Pushover']))- ->title((string)trans('email.admin_test_subject'))- ;+ return PushoverMessage::create((string) trans('email.admin_test_message', ['channel' => 'Pushover']))+ ->title((string) trans('email.admin_test_subject'));}/**diff --git a/app/Notifications/Test/OwnerTestNotificationSlack.php b/app/Notifications/Test/OwnerTestNotificationSlack.phpindex ea3dbab6d7..ee32e870f1 100644--- a/app/Notifications/Test/OwnerTestNotificationSlack.php+++ b/app/Notifications/Test/OwnerTestNotificationSlack.php@@ -47,11 +47,7 @@ class OwnerTestNotificationSlack extends Notification}/**- * Get the array representation of the notification.- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)- *- * @return array*/public function toArray(OwnerNotifiable $notifiable){@@ -60,8 +56,6 @@ class OwnerTestNotificationSlack extends Notification}/**- * Get the Slack representation of the notification.- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/public function toSlack(OwnerNotifiable $notifiable)@@ -71,11 +65,7 @@ class OwnerTestNotificationSlack extends Notification}/**- * Get the notification's delivery channels.- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)- *- * @return array*/public function via(OwnerNotifiable $notifiable){diff --git a/app/Notifications/Test/UserTestNotificationEmail.php b/app/Notifications/Test/UserTestNotificationEmail.phpindex 25463f8789..f3ab78154a 100644--- a/app/Notifications/Test/UserTestNotificationEmail.php+++ b/app/Notifications/Test/UserTestNotificationEmail.php@@ -24,7 +24,6 @@ declare(strict_types=1);namespace FireflyIII\Notifications\Test;-use FireflyIII\Notifications\Notifiables\OwnerNotifiable;use FireflyIII\User;use Illuminate\Bus\Queueable;use Illuminate\Notifications\Messages\MailMessage;@@ -46,11 +45,7 @@ class UserTestNotificationEmail extends Notification}/**- * Get the array representation of the notification.- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)- *- * @return array*/public function toArray(User $notifiable){@@ -58,33 +53,18 @@ class UserTestNotificationEmail extends Notification];}- /**- * Get the mail representation of the notification.- *- * @param mixed $notifiable- *- * @SuppressWarnings(PHPMD.UnusedFormalParameter)- *- * @return MailMessage- */+public function toMail(User $notifiable){$address = (string) $notifiable->email;return (new MailMessage())->markdown('emails.admin-test', ['email' => $address])- ->subject((string) trans('email.admin_test_subject'))- ;+ ->subject((string) trans('email.admin_test_subject'));}/**- * Get the notification's delivery channels.- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)- *- * @param User $notifiable- *- * @return array*/public function via(User $notifiable){diff --git a/app/Notifications/Test/UserTestNotificationNtfy.php b/app/Notifications/Test/UserTestNotificationNtfy.phpindex 5891701ed2..cbacae16f6 100644--- a/app/Notifications/Test/UserTestNotificationNtfy.php+++ b/app/Notifications/Test/UserTestNotificationNtfy.php@@ -49,13 +49,7 @@ class UserTestNotificationNtfy extends Notification}/**- * Get the array representation of the notification.- *- * @param User $notifiable- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)- *- * @return array*/public function toArray(User $notifiable){@@ -63,10 +57,13 @@ class UserTestNotificationNtfy extends Notification];}+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */public function toNtfy(User $user): Message{$settings = ReturnsSettings::getSettings('ntfy', 'user', $user);- $message = new Message();+ $message = new Message();$message->topic($settings['ntfy_topic']);$message->title((string) trans('email.admin_test_subject'));$message->body((string) trans('email.admin_test_message', ['channel' => 'ntfy']));diff --git a/app/Notifications/Test/UserTestNotificationPushover.php b/app/Notifications/Test/UserTestNotificationPushover.phpindex d694ae00ed..e2828ed7f8 100644--- a/app/Notifications/Test/UserTestNotificationPushover.php+++ b/app/Notifications/Test/UserTestNotificationPushover.php@@ -24,7 +24,6 @@ declare(strict_types=1);namespace FireflyIII\Notifications\Test;-use FireflyIII\Notifications\Notifiables\OwnerNotifiable;use FireflyIII\User;use Illuminate\Bus\Queueable;use Illuminate\Notifications\Notification;@@ -50,11 +49,7 @@ class UserTestNotificationPushover extends Notification}/**- * Get the array representation of the notification.- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)- *- * @return array*/public function toArray(User $notifiable){@@ -62,13 +57,15 @@ class UserTestNotificationPushover extends Notification];}+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */public function toPushover(User $notifiable): PushoverMessage{Log::debug('Now in (user) toPushover()');- return PushoverMessage::create((string)trans('email.admin_test_message', ['channel' => 'Pushover']))- ->title((string)trans('email.admin_test_subject'))- ;+ return PushoverMessage::create((string) trans('email.admin_test_message', ['channel' => 'Pushover']))+ ->title((string) trans('email.admin_test_subject'));}/**diff --git a/app/Notifications/Test/UserTestNotificationSlack.php b/app/Notifications/Test/UserTestNotificationSlack.phpindex 0d935bccce..5f6a02a836 100644--- a/app/Notifications/Test/UserTestNotificationSlack.php+++ b/app/Notifications/Test/UserTestNotificationSlack.php@@ -40,18 +40,16 @@ class UserTestNotificationSlack extends Notificationprivate OwnerNotifiable $owner;-+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */public function __construct(OwnerNotifiable $owner){$this->owner = $owner;}/**- * Get the array representation of the notification.- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)- *- * @return array*/public function toArray(OwnerNotifiable $notifiable){@@ -60,8 +58,6 @@ class UserTestNotificationSlack extends Notification}/**- * Get the Slack representation of the notification.- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)*/public function toSlack(OwnerNotifiable $notifiable)@@ -71,11 +67,7 @@ class UserTestNotificationSlack extends Notification}/**- * Get the notification's delivery channels.- ** @SuppressWarnings(PHPMD.UnusedFormalParameter)- *- * @return array*/public function via(OwnerNotifiable $notifiable){diff --git a/app/Notifications/User/BillReminder.php b/app/Notifications/User/BillReminder.phpindex 5b2cb849b9..0fa3dedd5a 100644--- a/app/Notifications/User/BillReminder.php+++ b/app/Notifications/User/BillReminder.php@@ -25,7 +25,7 @@ declare(strict_types=1);namespace FireflyIII\Notifications\User;use FireflyIII\Models\Bill;-use FireflyIII\Support\Notifications\UrlValidator;+use FireflyIII\Notifications\ReturnsAvailableChannels;use FireflyIII\User;use Illuminate\Bus\Queueable;use Illuminate\Notifications\Messages\MailMessage;@@ -52,58 +52,55 @@ class BillReminder extends Notification}- public function toArray($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toArray(User $notifiable){return [];}-- public function toMail($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toMail(User $notifiable){- $subject = (string)trans(sprintf('email.bill_warning_subject_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]);+ $subject = (string) trans(sprintf('email.bill_warning_subject_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]);if (0 === $this->diff) {- $subject = (string)trans(sprintf('email.bill_warning_subject_now_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]);+ $subject = (string) trans(sprintf('email.bill_warning_subject_now_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]);}return (new MailMessage())->markdown('emails.bill-warning', ['field' => $this->field, 'diff' => $this->diff, 'bill' => $this->bill])- ->subject($subject)- ;+ ->subject($subject);}-- public function toSlack($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toSlack(User $notifiable){- $message = (string)trans(sprintf('email.bill_warning_subject_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]);+ $message = (string) trans(sprintf('email.bill_warning_subject_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]);if (0 === $this->diff) {- $message = (string)trans(sprintf('email.bill_warning_subject_now_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]);+ $message = (string) trans(sprintf('email.bill_warning_subject_now_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]);}- $bill = $this->bill;- $url = route('bills.show', [$bill->id]);+ $bill = $this->bill;+ $url = route('bills.show', [$bill->id]);return (new SlackMessage())->warning()->attachment(static function ($attachment) use ($bill, $url): void {- $attachment->title((string)trans('firefly.visit_bill', ['name' => $bill->name]), $url);+ $attachment->title((string) trans('firefly.visit_bill', ['name' => $bill->name]), $url);})- ->content($message)- ;+ ->content($message);}-- public function via($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function via(User $notifiable){- /** @var null|User $user */- $user = auth()->user();- $slackUrl = null === $user ? '' : app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;- if (is_array($slackUrl)) {- $slackUrl = '';- }- if (UrlValidator::isValidWebhookURL((string)$slackUrl)) {- return ['mail', 'slack'];- }-- return ['mail'];+ return ReturnsAvailableChannels::returnChannels('user', $notifiable);}}diff --git a/app/Notifications/User/NewAccessToken.php b/app/Notifications/User/NewAccessToken.phpindex 126bc2f8c7..4144b19bf6 100644--- a/app/Notifications/User/NewAccessToken.php+++ b/app/Notifications/User/NewAccessToken.php@@ -24,7 +24,7 @@ declare(strict_types=1);namespace FireflyIII\Notifications\User;-use FireflyIII\Support\Notifications\UrlValidator;+use FireflyIII\Notifications\ReturnsAvailableChannels;use FireflyIII\User;use Illuminate\Bus\Queueable;use Illuminate\Notifications\Messages\MailMessage;@@ -42,40 +42,35 @@ class NewAccessToken extends Notificationpublic function __construct() {}- public function toArray($notifiable)+ public function toArray(User $notifiable){return [];}-- public function toMail($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toMail(User $notifiable){return (new MailMessage())->markdown('emails.token-created')- ->subject((string)trans('email.access_token_created_subject'))- ;+ ->subject((string) trans('email.access_token_created_subject'));}-- public function toSlack($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toSlack(User $notifiable){- return (new SlackMessage())->content((string)trans('email.access_token_created_body'));+ return (new SlackMessage())->content((string) trans('email.access_token_created_body'));}-- public function via($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function via(User $notifiable){- /** @var null|User $user */- $user = auth()->user();- $slackUrl = null === $user ? '' : app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;- if (is_array($slackUrl)) {- $slackUrl = '';- }- if (UrlValidator::isValidWebhookURL((string)$slackUrl)) {- return ['mail', 'slack'];- }-- return ['mail'];+ return ReturnsAvailableChannels::returnChannels('user', $notifiable);}}diff --git a/app/Notifications/User/RuleActionFailed.php b/app/Notifications/User/RuleActionFailed.phpindex 35ea148b1e..32c3a199a5 100644--- a/app/Notifications/User/RuleActionFailed.php+++ b/app/Notifications/User/RuleActionFailed.php@@ -24,7 +24,7 @@ declare(strict_types=1);namespace FireflyIII\Notifications\User;-use FireflyIII\Support\Notifications\UrlValidator;+use FireflyIII\Notifications\ReturnsAvailableChannels;use FireflyIII\User;use Illuminate\Bus\Queueable;use Illuminate\Notifications\Messages\SlackMessage;@@ -47,22 +47,26 @@ class RuleActionFailed extends Notificationpublic function __construct(array $params){[$mainMessage, $groupTitle, $groupLink, $ruleTitle, $ruleLink] = $params;- $this->message = $mainMessage;- $this->groupTitle = $groupTitle;- $this->groupLink = $groupLink;- $this->ruleTitle = $ruleTitle;- $this->ruleLink = $ruleLink;+ $this->message = $mainMessage;+ $this->groupTitle = $groupTitle;+ $this->groupLink = $groupLink;+ $this->ruleTitle = $ruleTitle;+ $this->ruleLink = $ruleLink;}-- public function toArray($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toArray(User $notifiable){return [];}-- public function toSlack($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toSlack(User $notifiable){$groupTitle = $this->groupTitle;$groupLink = $this->groupLink;@@ -70,28 +74,19 @@ class RuleActionFailed extends Notification$ruleLink = $this->ruleLink;return (new SlackMessage())->content($this->message)->attachment(static function ($attachment) use ($groupTitle, $groupLink): void {- $attachment->title((string)trans('rules.inspect_transaction', ['title' => $groupTitle]), $groupLink);+ $attachment->title((string) trans('rules.inspect_transaction', ['title' => $groupTitle]), $groupLink);})->attachment(static function ($attachment) use ($ruleTitle, $ruleLink): void {- $attachment->title((string)trans('rules.inspect_rule', ['title' => $ruleTitle]), $ruleLink);+ $attachment->title((string) trans('rules.inspect_rule', ['title' => $ruleTitle]), $ruleLink);});}- public function via($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function via(User $notifiable){- /** @var null|User $user */- $user = auth()->user();- $slackUrl = null === $user ? '' : app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;- if (is_array($slackUrl)) {- $slackUrl = '';- }- if (UrlValidator::isValidWebhookURL((string)$slackUrl)) {- app('log')->debug('Will send ruleActionFailed through Slack or Discord!');-- return ['slack'];- }- app('log')->debug('Will NOT send ruleActionFailed through Slack or Discord');-- return [];+ // todo disable mail channel+ return ReturnsAvailableChannels::returnChannels('user', $notifiable);}}diff --git a/app/Notifications/User/TransactionCreation.php b/app/Notifications/User/TransactionCreation.phpindex 61e2626d8a..4262543c7e 100644--- a/app/Notifications/User/TransactionCreation.php+++ b/app/Notifications/User/TransactionCreation.php@@ -24,6 +24,8 @@ declare(strict_types=1);namespace FireflyIII\Notifications\User;+use FireflyIII\Notifications\ReturnsAvailableChannels;+use FireflyIII\User;use Illuminate\Bus\Queueable;use Illuminate\Notifications\Messages\MailMessage;use Illuminate\Notifications\Notification;@@ -43,25 +45,33 @@ class TransactionCreation extends Notification$this->collection = $collection;}-- public function toArray($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toArray(User $notifiable){return [];}+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */- public function toMail($notifiable)+ public function toMail(User $notifiable){return (new MailMessage())->markdown('emails.report-new-journals', ['transformed' => $this->collection])- ->subject(trans_choice('email.new_journals_subject', count($this->collection)))- ;+ ->subject(trans_choice('email.new_journals_subject', count($this->collection)));}- public function via($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function via(User $notifiable){- return ['mail'];+ // todo only over email?+ return ReturnsAvailableChannels::returnChannels('user', $notifiable);}}diff --git a/app/Notifications/User/UserLogin.php b/app/Notifications/User/UserLogin.phpindex 3107748de0..82682e7c59 100644--- a/app/Notifications/User/UserLogin.php+++ b/app/Notifications/User/UserLogin.php@@ -25,7 +25,7 @@ declare(strict_types=1);namespace FireflyIII\Notifications\User;use FireflyIII\Exceptions\FireflyException;-use FireflyIII\Support\Notifications\UrlValidator;+use FireflyIII\Notifications\ReturnsAvailableChannels;use FireflyIII\User;use Illuminate\Bus\Queueable;use Illuminate\Notifications\Messages\MailMessage;@@ -48,16 +48,18 @@ class UserLogin extends Notification}- public function toArray($notifiable)+ public function toArray(User $notifiable){return [];}-- public function toMail($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toMail(User $notifiable){- $time = now(config('app.timezone'))->isoFormat((string)trans('config.date_time_js'));+ $time = now(config('app.timezone'))->isoFormat((string) trans('config.date_time_js'));$host = '';try {@@ -72,12 +74,13 @@ class UserLogin extends Notificationreturn (new MailMessage())->markdown('emails.new-ip', ['time' => $time, 'ipAddress' => $this->ip, 'host' => $host])- ->subject((string)trans('email.login_from_new_ip'))- ;+ ->subject((string) trans('email.login_from_new_ip'));}-- public function toSlack($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toSlack(User $notifiable){$host = '';@@ -91,22 +94,14 @@ class UserLogin extends Notification$host = $hostName;}- return (new SlackMessage())->content((string)trans('email.slack_login_from_new_ip', ['host' => $host, 'ip' => $this->ip]));+ return (new SlackMessage())->content((string) trans('email.slack_login_from_new_ip', ['host' => $host, 'ip' => $this->ip]));}-- public function via($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function via(User $notifiable){- /** @var null|User $user */- $user = auth()->user();- $slackUrl = null === $user ? '' : app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;- if (is_array($slackUrl)) {- $slackUrl = '';- }- if (UrlValidator::isValidWebhookURL((string)$slackUrl)) {- return ['mail', 'slack'];- }-- return ['mail'];+ return ReturnsAvailableChannels::returnChannels('user', $notifiable);}}diff --git a/app/Notifications/User/UserNewPassword.php b/app/Notifications/User/UserNewPassword.phpindex e75861add3..e7988763b7 100644--- a/app/Notifications/User/UserNewPassword.php+++ b/app/Notifications/User/UserNewPassword.php@@ -24,6 +24,8 @@ declare(strict_types=1);namespace FireflyIII\Notifications\User;+use FireflyIII\Notifications\ReturnsAvailableChannels;+use FireflyIII\User;use Illuminate\Bus\Queueable;use Illuminate\Notifications\Messages\MailMessage;use Illuminate\Notifications\Notification;@@ -43,25 +45,30 @@ class UserNewPassword extends Notification$this->url = $url;}-- public function toArray($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toArray(User $notifiable){return [];}-- public function toMail($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toMail(User $notifiable){return (new MailMessage())->markdown('emails.password', ['url' => $this->url])- ->subject((string)trans('email.reset_pw_subject'))- ;+ ->subject((string) trans('email.reset_pw_subject'));}-- public function via($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function via(User $notifiable){- return ['mail'];+ return ReturnsAvailableChannels::returnChannels('user', $notifiable);}}diff --git a/app/Notifications/User/UserRegistration.php b/app/Notifications/User/UserRegistration.phpindex bde33969f6..a973b4a7fc 100644--- a/app/Notifications/User/UserRegistration.php+++ b/app/Notifications/User/UserRegistration.php@@ -24,6 +24,8 @@ declare(strict_types=1);namespace FireflyIII\Notifications\User;+use FireflyIII\Notifications\ReturnsAvailableChannels;+use FireflyIII\User;use Illuminate\Bus\Queueable;use Illuminate\Notifications\Messages\MailMessage;use Illuminate\Notifications\Notification;@@ -38,25 +40,30 @@ class UserRegistration extends Notificationpublic function __construct() {}-- public function toArray($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toArray(User $notifiable){return [];}-- public function toMail($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function toMail(User $notifiable){return (new MailMessage())->markdown('emails.registered', ['address' => route('index')])- ->subject((string)trans('email.registered_subject'))- ;+ ->subject((string) trans('email.registered_subject'));}-- public function via($notifiable)+ /**+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)+ */+ public function via(User $notifiable){- return ['mail'];+ return ReturnsAvailableChannels::returnChannels('user', $notifiable);}}