From cd37ea7a9312c0a436fdbc350f7d3e4307b81eb0 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Wed, 9 Oct 2024 21:53:26 +0200 Subject: [PATCH 1/3] use IAppConfig Signed-off-by: dartcafe --- lib/AppInfo/Application.php | 4 +- lib/Model/Mail/MailBase.php | 9 ++-- lib/Model/Settings/AppSettings.php | 75 ++++++++++++++---------------- lib/Service/SettingsService.php | 50 +++++++++++--------- 4 files changed, 71 insertions(+), 67 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index b0ba1217d..9a41b6daf 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -62,7 +62,7 @@ use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\Group\Events\GroupDeletedEvent; -use OCP\IConfig; +use OCP\IAppConfig; use OCP\IDBConnection; use OCP\IUserManager; use OCP\User\Events\UserDeletedEvent; @@ -143,7 +143,7 @@ private function registerServices(IRegistrationContext $context): void { $context->registerService(AppSettings::class, function (ContainerInterface $c): AppSettings { return new AppSettings( - $c->get(IConfig::class), + $c->get(IAppConfig::class), $c->get(UserSession::class), ); }); diff --git a/lib/Model/Mail/MailBase.php b/lib/Model/Mail/MailBase.php index 47ccfc1fc..8edfaeedf 100644 --- a/lib/Model/Mail/MailBase.php +++ b/lib/Model/Mail/MailBase.php @@ -21,6 +21,7 @@ use OCA\Polls\Helper\Container; use OCA\Polls\Model\Settings\AppSettings; use OCA\Polls\Model\UserBase; +use OCP\IAppConfig; use OCP\IL10N; use OCP\L10N\IFactory; use OCP\Mail\IEMailTemplate; @@ -31,6 +32,7 @@ abstract class MailBase { /** @var string */ protected const TEMPLATE_CLASS = AppConstants::APP_ID . '.Mail'; + protected IAppConfig $appConfig; protected AppSettings $appSettings; protected IEmailTemplate $emailTemplate; protected IL10N $l10n; @@ -55,6 +57,7 @@ public function __construct( * setUp */ private function setUp(): void { + $this->appConfig = Container::queryClass(IAppConfig::class); $this->appSettings = Container::queryClass(AppSettings::class); $this->logger = Container::queryClass(LoggerInterface::class); $this->mailer = Container::queryClass(IMailer::class); @@ -115,12 +118,12 @@ private function getEmailTemplate() : IEMailTemplate { // add footer $footerText = $this->getFooter(); - if ($this->appSettings->getBooleanSetting(AppSettings::SETTING_LEGAL_TERMS_IN_EMAIL)) { + if ($this->appConfig->getValueString(AppConstants::APP_ID, AppSettings::SETTING_LEGAL_TERMS_IN_EMAIL)) { $footerText = $footerText . '
' . $this->getLegalLinks(); } - if ($this->appSettings->getStringSetting(AppSettings::SETTING_DISCLAIMER)) { - $footerText = $footerText . '
' . $this->getParsedMarkDown($this->appSettings->getStringSetting(AppSettings::SETTING_DISCLAIMER)); + if ($this->appConfig->getValueString(AppConstants::APP_ID, AppSettings::SETTING_DISCLAIMER)) { + $footerText = $footerText . '
' . $this->getParsedMarkDown($this->appConfig->getValueString(AppConstants::APP_ID, AppSettings::SETTING_DISCLAIMER)); } $this->emailTemplate->addFooter($footerText); diff --git a/lib/Model/Settings/AppSettings.php b/lib/Model/Settings/AppSettings.php index b87ef1421..c602aebb4 100644 --- a/lib/Model/Settings/AppSettings.php +++ b/lib/Model/Settings/AppSettings.php @@ -12,7 +12,8 @@ use OCA\Polls\AppConstants; use OCA\Polls\Model\Group\Group; use OCA\Polls\UserSession; -use OCP\IConfig; +// use OCP\AppFramework\Services\IAppConfig; +use OCP\IAppConfig; class AppSettings implements JsonSerializable { public const SETTING_ALLOW_PUBLIC_SHARES = 'allowPublicShares'; @@ -47,27 +48,41 @@ class AppSettings implements JsonSerializable { public const SETTING_UPDATE_TYPE_DEFAULT = self::SETTING_UPDATE_TYPE_NO_POLLING; public function __construct( - private IConfig $config, + private IAppConfig $appConfig, private UserSession $userSession, ) { } + + private function checkSettingType(string $key, int $type): bool { + return $this->appConfig->getValueType(AppConstants::APP_ID, $key) === $type; + } + // Getters // generic Setters public function getBooleanSetting(string $key, bool $default = true): bool { - return $this->stringToBool($this->config->getAppValue(AppConstants::APP_ID, $key), $default); + if ($this->checkSettingType($key, IAppConfig::VALUE_BOOL)) { + return $this->appConfig->getValueBool(AppConstants::APP_ID, $key); + } + return $this->stringToBool($this->appConfig->getValueString(AppConstants::APP_ID, $key), $default); } public function getGroupSetting(string $key): array { - return $this->stringToArray($this->config->getAppValue(AppConstants::APP_ID, $key)); + if ($this->checkSettingType($key, IAppConfig::VALUE_ARRAY)) { + return $this->appConfig->getValueArray(AppConstants::APP_ID, $key, []); + } + return $this->stringToArray($this->appConfig->getValueString(AppConstants::APP_ID, $key)); } public function getStringSetting(string $key, string $default = ''): string { - return $this->config->getAppValue(AppConstants::APP_ID, $key) ?: $default; + return $this->appConfig->getValueString(AppConstants::APP_ID, $key, $default); } public function getIntegerSetting(string $key, int $default = 0): int { - return $this->stringToInteger($this->config->getAppValue(AppConstants::APP_ID, $key), $default); + if ($this->checkSettingType($key, IAppConfig::VALUE_INT)) { + return $this->appConfig->getValueInt(AppConstants::APP_ID, $key, $default); + } + return $this->stringToInteger($this->appConfig->getValueString(AppConstants::APP_ID, $key), $default); } // Checks @@ -133,17 +148,19 @@ public function getComboAllowed(): bool { } public function getUsePrivacyUrl(): string { - if ($this->config->getAppValue(AppConstants::APP_ID, self::SETTING_PRIVACY_URL)) { - return $this->config->getAppValue(AppConstants::APP_ID, self::SETTING_PRIVACY_URL); + $ownSetting = $this->appConfig->getValueString(AppConstants::APP_ID, self::SETTING_PRIVACY_URL); + if ($ownSetting === '') { + return $ownSetting; } - return $this->config->getAppValue('theming', 'privacyUrl'); + return $this->appConfig->getValueString('theming', 'privacyUrl'); } public function getUseImprintUrl(): string { - if ($this->config->getAppValue(AppConstants::APP_ID, self::SETTING_IMPRINT_URL)) { - return $this->config->getAppValue(AppConstants::APP_ID, self::SETTING_IMPRINT_URL); + $ownSetting = $this->appConfig->getValueString(AppConstants::APP_ID, self::SETTING_IMPRINT_URL); + if ($ownSetting === '') { + return $ownSetting; } - return $this->config->getAppValue('theming', 'imprintUrl'); + return $this->appConfig->getValueString('theming', 'imprintUrl'); } public function getAutoarchiveOffset(): int { @@ -151,7 +168,7 @@ public function getAutoarchiveOffset(): int { } public function getUpdateType(): string { - return $this->getStringSetting(self::SETTING_UPDATE_TYPE, self::SETTING_UPDATE_TYPE_DEFAULT); + return $this->appConfig->getValueString(AppConstants::APP_ID, self::SETTING_UPDATE_TYPE, self::SETTING_UPDATE_TYPE_DEFAULT); } public function getShowLogin(): bool { @@ -165,20 +182,6 @@ public function getLoadPollsInNavigation(): bool { return $this->getBooleanSetting(self::SETTING_LOAD_POLLS_IN_NAVIGATION); } - // Setters - // generic setters - public function setBooleanSetting(string $key, bool $value): void { - $this->config->setAppValue(AppConstants::APP_ID, $key, $this->boolToString($value)); - } - - public function setGroupSetting(string $key, array $value): void { - $this->config->setAppValue(AppConstants::APP_ID, $key, json_encode($value)); - } - - public function setStringSetting(string $key, string $value): void { - $this->config->setAppValue(AppConstants::APP_ID, $key, $value); - } - /** * @return array * @@ -236,14 +239,15 @@ public function jsonSerialize(): array { self::SETTING_COMBO_GROUPS => $comboGroups, self::SETTING_AUTO_ARCHIVE => $this->getBooleanSetting(self::SETTING_AUTO_ARCHIVE), self::SETTING_AUTO_ARCHIVE_OFFSET => $this->getAutoarchiveOffset(), - self::SETTING_DISCLAIMER => $this->getStringSetting(self::SETTING_DISCLAIMER), - self::SETTING_IMPRINT_URL => $this->getStringSetting(self::SETTING_IMPRINT_URL), - self::SETTING_PRIVACY_URL => $this->getStringSetting(self::SETTING_PRIVACY_URL), + self::SETTING_DISCLAIMER => $this->appConfig->getValueString(AppConstants::APP_ID, self::SETTING_DISCLAIMER), + self::SETTING_IMPRINT_URL => $this->appConfig->getValueString(AppConstants::APP_ID, self::SETTING_IMPRINT_URL), + self::SETTING_PRIVACY_URL => $this->appConfig->getValueString(AppConstants::APP_ID, self::SETTING_PRIVACY_URL), self::SETTING_UPDATE_TYPE => $this->getUpdateType(), + 'storedKeys' => $this->appConfig->getKeys(AppConstants::APP_ID), 'usePrivacyUrl' => $this->getUsePrivacyUrl(), 'useImprintUrl' => $this->getUseImprintUrl(), - 'defaultPrivacyUrl' => $this->config->getAppValue('theming', 'privacyUrl'), - 'defaultImprintUrl' => $this->config->getAppValue('theming', 'imprintUrl'), + 'defaultPrivacyUrl' => $this->appConfig->getValueString('theming', 'privacyUrl'), + 'defaultImprintUrl' => $this->appConfig->getValueString('theming', 'imprintUrl'), ]; } @@ -277,11 +281,4 @@ private function stringToBool(string $value, bool $default): bool { default => $default, }; } - - private function boolToString(?bool $value): string { - if ($value) { - return 'yes'; - } - return 'no'; - } } diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php index bb6e81c0d..e86741ace 100644 --- a/lib/Service/SettingsService.php +++ b/lib/Service/SettingsService.php @@ -8,7 +8,9 @@ namespace OCA\Polls\Service; +use OCA\Polls\AppConstants; use OCA\Polls\Model\Settings\AppSettings; +use OCP\IAppConfig; class SettingsService { @@ -17,6 +19,7 @@ class SettingsService { */ public function __construct( private AppSettings $appSettings, + private IAppConfig $appConfig, ) { } @@ -31,29 +34,30 @@ public function getAppSettings(): AppSettings { * Write app settings */ public function writeAppSettings(array $settingsArray): void { - $this->appSettings->setBooleanSetting(AppSettings::SETTING_SHOW_MAIL_ADDRESSES, $settingsArray[AppSettings::SETTING_SHOW_MAIL_ADDRESSES]); - $this->appSettings->setBooleanSetting(AppSettings::SETTING_ALLOW_PUBLIC_SHARES, $settingsArray[AppSettings::SETTING_ALLOW_PUBLIC_SHARES]); - $this->appSettings->setBooleanSetting(AppSettings::SETTING_ALLOW_COMBO, $settingsArray[AppSettings::SETTING_ALLOW_COMBO]); - $this->appSettings->setBooleanSetting(AppSettings::SETTING_ALLOW_ALL_ACCESS, $settingsArray[AppSettings::SETTING_ALLOW_ALL_ACCESS]); - $this->appSettings->setBooleanSetting(AppSettings::SETTING_ALLOW_POLL_CREATION, $settingsArray[AppSettings::SETTING_ALLOW_POLL_CREATION]); - $this->appSettings->setBooleanSetting(AppSettings::SETTING_ALLOW_POLL_DOWNLOAD, $settingsArray[AppSettings::SETTING_ALLOW_POLL_DOWNLOAD]); - $this->appSettings->setBooleanSetting(AppSettings::SETTING_AUTO_ARCHIVE, $settingsArray[AppSettings::SETTING_AUTO_ARCHIVE]); - $this->appSettings->setBooleanSetting(AppSettings::SETTING_SHOW_LOGIN, $settingsArray[AppSettings::SETTING_SHOW_LOGIN]); - $this->appSettings->setBooleanSetting(AppSettings::SETTING_USE_ACTIVITY, $settingsArray[AppSettings::SETTING_USE_ACTIVITY]); - $this->appSettings->setBooleanSetting(AppSettings::SETTING_LEGAL_TERMS_IN_EMAIL, $settingsArray[AppSettings::SETTING_LEGAL_TERMS_IN_EMAIL]); - $this->appSettings->setBooleanSetting(AppSettings::SETTING_LOAD_POLLS_IN_NAVIGATION, $settingsArray[AppSettings::SETTING_LOAD_POLLS_IN_NAVIGATION]); - - $this->appSettings->setGroupSetting(AppSettings::SETTING_SHOW_MAIL_ADDRESSES_GROUPS, array_column($settingsArray[AppSettings::SETTING_SHOW_MAIL_ADDRESSES_GROUPS], 'id')); - $this->appSettings->setGroupSetting(AppSettings::SETTING_ALL_ACCESS_GROUPS, array_column($settingsArray[AppSettings::SETTING_ALL_ACCESS_GROUPS], 'id')); - $this->appSettings->setGroupSetting(AppSettings::SETTING_PUBLIC_SHARES_GROUPS, array_column($settingsArray[AppSettings::SETTING_PUBLIC_SHARES_GROUPS], 'id')); - $this->appSettings->setGroupSetting(AppSettings::SETTING_COMBO_GROUPS, array_column($settingsArray[AppSettings::SETTING_COMBO_GROUPS], 'id')); - $this->appSettings->setGroupSetting(AppSettings::SETTING_POLL_CREATION_GROUPS, array_column($settingsArray[AppSettings::SETTING_POLL_CREATION_GROUPS], 'id')); - $this->appSettings->setGroupSetting(AppSettings::SETTING_POLL_DOWNLOAD_GROUPS, array_column($settingsArray[AppSettings::SETTING_POLL_DOWNLOAD_GROUPS], 'id')); + $this->appConfig->setValueBool(AppConstants::APP_ID, AppSettings::SETTING_SHOW_MAIL_ADDRESSES, $settingsArray[AppSettings::SETTING_SHOW_MAIL_ADDRESSES]); + $this->appConfig->setValueBool(AppConstants::APP_ID, AppSettings::SETTING_ALLOW_PUBLIC_SHARES, $settingsArray[AppSettings::SETTING_ALLOW_PUBLIC_SHARES]); + $this->appConfig->setValueBool(AppConstants::APP_ID, AppSettings::SETTING_ALLOW_COMBO, $settingsArray[AppSettings::SETTING_ALLOW_COMBO]); + $this->appConfig->setValueBool(AppConstants::APP_ID, AppSettings::SETTING_ALLOW_ALL_ACCESS, $settingsArray[AppSettings::SETTING_ALLOW_ALL_ACCESS]); + $this->appConfig->setValueBool(AppConstants::APP_ID, AppSettings::SETTING_ALLOW_POLL_CREATION, $settingsArray[AppSettings::SETTING_ALLOW_POLL_CREATION]); + $this->appConfig->setValueBool(AppConstants::APP_ID, AppSettings::SETTING_ALLOW_POLL_DOWNLOAD, $settingsArray[AppSettings::SETTING_ALLOW_POLL_DOWNLOAD]); + $this->appConfig->setValueBool(AppConstants::APP_ID, AppSettings::SETTING_AUTO_ARCHIVE, $settingsArray[AppSettings::SETTING_AUTO_ARCHIVE]); + $this->appConfig->setValueBool(AppConstants::APP_ID, AppSettings::SETTING_SHOW_LOGIN, $settingsArray[AppSettings::SETTING_SHOW_LOGIN]); + $this->appConfig->setValueBool(AppConstants::APP_ID, AppSettings::SETTING_USE_ACTIVITY, $settingsArray[AppSettings::SETTING_USE_ACTIVITY]); + $this->appConfig->setValueBool(AppConstants::APP_ID, AppSettings::SETTING_LEGAL_TERMS_IN_EMAIL, $settingsArray[AppSettings::SETTING_LEGAL_TERMS_IN_EMAIL]); + $this->appConfig->setValueBool(AppConstants::APP_ID, AppSettings::SETTING_LOAD_POLLS_IN_NAVIGATION, $settingsArray[AppSettings::SETTING_LOAD_POLLS_IN_NAVIGATION]); + + $this->appConfig->setValueArray(AppConstants::APP_ID, AppSettings::SETTING_SHOW_MAIL_ADDRESSES_GROUPS, array_column($settingsArray[AppSettings::SETTING_SHOW_MAIL_ADDRESSES_GROUPS], 'id')); + $this->appConfig->setValueArray(AppConstants::APP_ID, AppSettings::SETTING_ALL_ACCESS_GROUPS, array_column($settingsArray[AppSettings::SETTING_ALL_ACCESS_GROUPS], 'id')); + $this->appConfig->setValueArray(AppConstants::APP_ID, AppSettings::SETTING_PUBLIC_SHARES_GROUPS, array_column($settingsArray[AppSettings::SETTING_PUBLIC_SHARES_GROUPS], 'id')); + $this->appConfig->setValueArray(AppConstants::APP_ID, AppSettings::SETTING_COMBO_GROUPS, array_column($settingsArray[AppSettings::SETTING_COMBO_GROUPS], 'id')); + $this->appConfig->setValueArray(AppConstants::APP_ID, AppSettings::SETTING_POLL_CREATION_GROUPS, array_column($settingsArray[AppSettings::SETTING_POLL_CREATION_GROUPS], 'id')); + $this->appConfig->setValueArray(AppConstants::APP_ID, AppSettings::SETTING_POLL_DOWNLOAD_GROUPS, array_column($settingsArray[AppSettings::SETTING_POLL_DOWNLOAD_GROUPS], 'id')); - $this->appSettings->setStringSetting(AppSettings::SETTING_AUTO_ARCHIVE_OFFSET, strval($settingsArray[AppSettings::SETTING_AUTO_ARCHIVE_OFFSET])); - $this->appSettings->setStringSetting(AppSettings::SETTING_UPDATE_TYPE, $settingsArray[AppSettings::SETTING_UPDATE_TYPE]); - $this->appSettings->setStringSetting(AppSettings::SETTING_PRIVACY_URL, $settingsArray[AppSettings::SETTING_PRIVACY_URL]); - $this->appSettings->setStringSetting(AppSettings::SETTING_IMPRINT_URL, $settingsArray[AppSettings::SETTING_IMPRINT_URL]); - $this->appSettings->setStringSetting(AppSettings::SETTING_DISCLAIMER, $settingsArray[AppSettings::SETTING_DISCLAIMER]); + $this->appConfig->setValueInt(AppConstants::APP_ID, AppSettings::SETTING_AUTO_ARCHIVE_OFFSET, $settingsArray[AppSettings::SETTING_AUTO_ARCHIVE_OFFSET]); + + $this->appConfig->setValueString(AppConstants::APP_ID, AppSettings::SETTING_UPDATE_TYPE, $settingsArray[AppSettings::SETTING_UPDATE_TYPE]); + $this->appConfig->setValueString(AppConstants::APP_ID, AppSettings::SETTING_PRIVACY_URL, $settingsArray[AppSettings::SETTING_PRIVACY_URL]); + $this->appConfig->setValueString(AppConstants::APP_ID, AppSettings::SETTING_IMPRINT_URL, $settingsArray[AppSettings::SETTING_IMPRINT_URL]); + $this->appConfig->setValueString(AppConstants::APP_ID, AppSettings::SETTING_DISCLAIMER, $settingsArray[AppSettings::SETTING_DISCLAIMER]); } } From c1f689563a446b5a4f246bbcb29ccd30c3147de9 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Wed, 9 Oct 2024 22:46:37 +0200 Subject: [PATCH 2/3] monk mode: removed some psalm infos Signed-off-by: dartcafe --- lib/Db/Poll.php | 2 +- lib/Db/Preferences.php | 7 +++++-- lib/Filter/ActivityFilter.php | 3 +++ lib/Model/Group/Circle.php | 2 +- lib/Model/Group/Group.php | 8 +++++++- lib/Model/Settings/AppSettings.php | 4 ---- lib/Model/UserBase.php | 2 +- lib/Service/MailService.php | 2 +- lib/Service/ShareService.php | 6 +++--- lib/Settings/ActivityVote.php | 3 +++ psalm-baseline.xml | 21 +-------------------- 11 files changed, 26 insertions(+), 34 deletions(-) diff --git a/lib/Db/Poll.php b/lib/Db/Poll.php index 8094a4d5c..8f7b6926f 100644 --- a/lib/Db/Poll.php +++ b/lib/Db/Poll.php @@ -355,7 +355,7 @@ public function setUserId(string $userId): void { } public function getGroupShares(): array { - if (!empty($this->groupShares)) { + if ($this->groupShares !== null && $this->groupShares !== '') { // explode with separator and remove empty elements return array_filter(explode(PollMapper::CONCAT_SEPARATOR, PollMapper::CONCAT_SEPARATOR . $this->groupShares)); } diff --git a/lib/Db/Preferences.php b/lib/Db/Preferences.php index 85bfd8f55..b4053010e 100644 --- a/lib/Db/Preferences.php +++ b/lib/Db/Preferences.php @@ -19,7 +19,6 @@ * @method void setUserId(string $value) * @method string getTimestamp() * @method void setTimestamp(int $value) - * @method string getPreferences() * @method void setPreferences(string $value) */ class Preferences extends Entity implements JsonSerializable { @@ -52,8 +51,12 @@ public function __construct() { $this->setPreferences(json_encode(self::DEFAULT)); } + public function getPreferences(): string { + return $this->preferences ?? ''; + } + public function getPreferences_decoded(): mixed { - return json_decode($this->getPreferences() ?? ''); + return json_decode($this->getPreferences()); } public function getCheckCalendarsHoursBefore(): int { diff --git a/lib/Filter/ActivityFilter.php b/lib/Filter/ActivityFilter.php index b6b3d99ac..4085a4676 100644 --- a/lib/Filter/ActivityFilter.php +++ b/lib/Filter/ActivityFilter.php @@ -16,6 +16,9 @@ use OCP\IL10N; use OCP\IURLGenerator; +/** + * @psalm-suppress UnusedClass + */ class ActivityFilter implements \OCP\Activity\IFilter { private $l10n; private $urlGenerator; diff --git a/lib/Model/Group/Circle.php b/lib/Model/Group/Circle.php index c378a718e..c0ff76023 100644 --- a/lib/Model/Group/Circle.php +++ b/lib/Model/Group/Circle.php @@ -18,7 +18,7 @@ use OCA\Polls\Model\UserBase; /** - * @psam-supress + * @psalm-suppress UnusedClass */ class Circle extends UserBase { public const TYPE = 'circle'; diff --git a/lib/Model/Group/Group.php b/lib/Model/Group/Group.php index b729ecd32..10ef20474 100644 --- a/lib/Model/Group/Group.php +++ b/lib/Model/Group/Group.php @@ -8,6 +8,7 @@ namespace OCA\Polls\Model\Group; +use OCA\Polls\Exceptions\NotFoundException; use OCA\Polls\Helper\Container; use OCA\Polls\Model\User\User; use OCA\Polls\Model\UserBase; @@ -30,7 +31,12 @@ public function __construct( } private function setUp(): void { - $this->group = $this->groupManager->get($this->id); + $foundGroup = $this->groupManager->get($this->id); + if ($foundGroup === null) { + throw new NotFoundException('Group not found'); + } + + $this->group = $foundGroup; $this->displayName = $this->group->getDisplayName(); } diff --git a/lib/Model/Settings/AppSettings.php b/lib/Model/Settings/AppSettings.php index c602aebb4..90af209c5 100644 --- a/lib/Model/Settings/AppSettings.php +++ b/lib/Model/Settings/AppSettings.php @@ -74,10 +74,6 @@ public function getGroupSetting(string $key): array { return $this->stringToArray($this->appConfig->getValueString(AppConstants::APP_ID, $key)); } - public function getStringSetting(string $key, string $default = ''): string { - return $this->appConfig->getValueString(AppConstants::APP_ID, $key, $default); - } - public function getIntegerSetting(string $key, int $default = 0): int { if ($this->checkSettingType($key, IAppConfig::VALUE_INT)) { return $this->appConfig->getValueInt(AppConstants::APP_ID, $key, $default); diff --git a/lib/Model/UserBase.php b/lib/Model/UserBase.php index 1e9c55bbb..5c48ac696 100644 --- a/lib/Model/UserBase.php +++ b/lib/Model/UserBase.php @@ -242,7 +242,7 @@ public static function search(string $query = ''): array { $types[] = IShare::TYPE_CIRCLE; } - [$result, $more] = Container::queryClass(ISearch::class)->search($query, $types, false, 200, 0); + [$result] = Container::queryClass(ISearch::class)->search($query, $types, false, 200, 0); foreach (($result['users'] ?? []) as $item) { $items[] = new User($item['value']['shareWith']); diff --git a/lib/Service/MailService.php b/lib/Service/MailService.php index 4b89319b6..ee929ec91 100644 --- a/lib/Service/MailService.php +++ b/lib/Service/MailService.php @@ -102,7 +102,7 @@ public static function extractEmailAddressAndName($eMailString): array { preg_match(self::REGEX_PARSE_MAIL_AND_NAME, $eMailString, $matches); // Check if the found element is a valid email address - $emailAddress = !empty($matches[1]) ? trim($matches[1]) : null; + $emailAddress = boolval($matches[1]) ? trim($matches[1]) : null; if ($emailAddress !== null && filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) { // Extract the name based on the input string diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index 4797003d1..f65f34af0 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -314,14 +314,14 @@ private function convertPersonalPublicShareToExternalShare( $this->share->setDisplayName($displayName ?? $this->share->getDisplayName()); $this->share->setTimeZoneName($timeZone ?? $this->share->getTimeZoneName()); $this->share->setLanguage($language ?? $this->share->getLanguage()); - - if ($emailAddress && $emailAddress !== $this->share->getEmailAddress()) { + + if ($emailAddress !== null && $emailAddress !== '' && $emailAddress !== $this->share->getEmailAddress()) { // reset invitation sent, if email address is changed $this->share->setInvitationSent(0); } - $this->share->setEmailAddress($emailAddress ?? $this->share->getEmailAddress()); + // convert to type external $this->share->setType(Share::TYPE_EXTERNAL); diff --git a/lib/Settings/ActivityVote.php b/lib/Settings/ActivityVote.php index 55af8f23f..691ee7521 100644 --- a/lib/Settings/ActivityVote.php +++ b/lib/Settings/ActivityVote.php @@ -8,6 +8,9 @@ namespace OCA\Polls\Settings; +/** + * @psalm-suppress UnusedClass + */ class ActivityVote extends ActivitySettings { public function getIdentifier() : string { return 'vote_set'; diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 489da69cb..3c4f956d5 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,33 +1,14 @@ - - - - - - - + circle]]> - - - - - - - - - - From 872cf60b3d75463013ae09c31fb14e348d1a356e Mon Sep 17 00:00:00 2001 From: dartcafe Date: Wed, 9 Oct 2024 22:50:03 +0200 Subject: [PATCH 3/3] licence Signed-off-by: dartcafe --- psalm-baseline.xml.license | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 psalm-baseline.xml.license diff --git a/psalm-baseline.xml.license b/psalm-baseline.xml.license new file mode 100644 index 000000000..e8d85e638 --- /dev/null +++ b/psalm-baseline.xml.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: 2021 Nextcloud contributors +SPDX-License-Identifier: AGPL-3.0-or-later