diff --git a/apps/encryption/lib/Recovery.php b/apps/encryption/lib/Recovery.php index f4336ec7c4e0a..1bcb9394dd81c 100644 --- a/apps/encryption/lib/Recovery.php +++ b/apps/encryption/lib/Recovery.php @@ -169,7 +169,7 @@ public function isRecoveryEnabledForUser($user = '') { * @return bool */ public function isRecoveryKeyEnabled() { - $enabled = $this->config->getAppValue('encryption', 'recoveryAdminEnabled', 0); + $enabled = $this->config->getAppValue('encryption', 'recoveryAdminEnabled', '0'); return ($enabled === '1'); } diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index cfbc9afce2b07..f93a19bae67bd 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -315,10 +315,10 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal $params['allowShareWithLink'] = $this->shareManager->shareApiAllowLinks() ? 'yes' : 'no'; $params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name'); $params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc'); - $params['showgridview'] = $this->config->getUserValue($user, 'files', 'show_grid', false); - $showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false); + $params['showgridview'] = $this->config->getUserValue($user, 'files', 'show_grid', 'false'); + $showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', 'false'); $params['showHiddenFiles'] = $showHidden ? 1 : 0; - $cropImagePreviews = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', true); + $cropImagePreviews = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', 'true'); $params['cropImagePreviews'] = $cropImagePreviews ? 1 : 0; $params['fileNotFound'] = $fileNotFound ? 1 : 0; $params['appNavigation'] = $nav; diff --git a/apps/files/list.php b/apps/files/list.php index c4b93b2e145dc..04833e11d3dae 100644 --- a/apps/files/list.php +++ b/apps/files/list.php @@ -34,7 +34,7 @@ $shareManager = Server::get(IManager::class); $publicUploadEnabled = $shareManager->shareApiLinkAllowPublicUpload() ? 'yes' : 'no'; -$showgridview = $config->getUserValue($userSession->getUser()->getUID(), 'files', 'show_grid', false); +$showgridview = $config->getUserValue($userSession->getUser()->getUID(), 'files', 'show_grid', 'false'); // renders the controls and table headers template $tmpl = new OCP\Template('files', 'list', ''); diff --git a/apps/files/recentlist.php b/apps/files/recentlist.php index 874ecca957cb0..e24d5946e387e 100644 --- a/apps/files/recentlist.php +++ b/apps/files/recentlist.php @@ -27,7 +27,7 @@ $config = \OC::$server->getConfig(); $userSession = \OC::$server->getUserSession(); -$showgridview = $config->getUserValue($userSession->getUser()->getUID(), 'files', 'show_grid', false); +$showgridview = $config->getUserValue($userSession->getUser()->getUID(), 'files', 'show_grid', 'false'); $tmpl = new OCP\Template('files', 'recentlist', ''); diff --git a/apps/files/simplelist.php b/apps/files/simplelist.php index b20bdcc9c63f1..0eeae50d1f967 100644 --- a/apps/files/simplelist.php +++ b/apps/files/simplelist.php @@ -25,7 +25,7 @@ $config = \OC::$server->getConfig(); $userSession = \OC::$server->getUserSession(); -$showgridview = $config->getUserValue($userSession->getUser()->getUID(), 'files', 'show_grid', false); +$showgridview = $config->getUserValue($userSession->getUser()->getUID(), 'files', 'show_grid', 'false'); // renders the controls and table headers template $tmpl = new OCP\Template('files', 'simplelist', ''); diff --git a/apps/files_sharing/list.php b/apps/files_sharing/list.php index f43aed214278f..50942e0050ede 100644 --- a/apps/files_sharing/list.php +++ b/apps/files_sharing/list.php @@ -30,7 +30,7 @@ $config = Server::get(IConfig::class); $userSession = Server::get(IUserSession::class); -$showgridview = $config->getUserValue($userSession->getUser()->getUID(), 'files', 'show_grid', false); +$showgridview = $config->getUserValue($userSession->getUser()->getUID(), 'files', 'show_grid', 'false'); $tmpl = new OCP\Template('files_sharing', 'list', ''); diff --git a/apps/files_trashbin/list.php b/apps/files_trashbin/list.php index 117d3b4ddfeb7..545040e77489a 100644 --- a/apps/files_trashbin/list.php +++ b/apps/files_trashbin/list.php @@ -28,7 +28,7 @@ $config = \OC::$server->getConfig(); $userSession = \OC::$server->getUserSession(); -$showgridview = $config->getUserValue($userSession->getUser()->getUID(), 'files', 'show_grid', false); +$showgridview = $config->getUserValue($userSession->getUser()->getUID(), 'files', 'show_grid', 'false'); $tmpl = new OCP\Template('files_trashbin', 'index', ''); diff --git a/apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php b/apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php index 39d8118abe71d..4a259abd3fae5 100644 --- a/apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php +++ b/apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php @@ -180,7 +180,7 @@ protected function run($argument): void { $user->getUID(), 'lookup_server_connector', 'update_retries', - $this->retries + 1 + (string)($this->retries + 1) ); } } diff --git a/apps/theming/lib/Migration/MigrateUserConfig.php b/apps/theming/lib/Migration/MigrateUserConfig.php index 0f8d982dfa70f..022a4449e7e66 100644 --- a/apps/theming/lib/Migration/MigrateUserConfig.php +++ b/apps/theming/lib/Migration/MigrateUserConfig.php @@ -91,20 +91,18 @@ public function run(IOutput $output) { $this->userManager->callForSeenUsers(function (IUser $user) use ($output) { $config = []; - $font = $this->config->getUserValue($user->getUID(), 'accessibility', 'font', false); - $highcontrast = $this->config->getUserValue($user->getUID(), 'accessibility', 'highcontrast', false); - $theme = $this->config->getUserValue($user->getUID(), 'accessibility', 'theme', false); - - if ($highcontrast || $theme) { - if ($theme === 'dark' && $highcontrast === 'highcontrast') { - $config[] = $this->darkHighContrastTheme->getId(); - } else if ($theme === 'dark') { - $config[] = $this->darkTheme->getId(); - } else if ($highcontrast === 'highcontrast') { - $config[] = $this->highContrastTheme->getId(); - } + $font = $this->config->getUserValue($user->getUID(), 'accessibility', 'font', ''); + $highcontrast = $this->config->getUserValue($user->getUID(), 'accessibility', 'highcontrast', ''); + $theme = $this->config->getUserValue($user->getUID(), 'accessibility', 'theme', ''); + + if ($theme === 'dark' && $highcontrast === 'highcontrast') { + $config[] = $this->darkHighContrastTheme->getId(); + } else if ($theme === 'dark') { + $config[] = $this->darkTheme->getId(); + } else if ($highcontrast === 'highcontrast') { + $config[] = $this->highContrastTheme->getId(); } - + if ($font === 'fontdyslexic') { $config[] = $this->dyslexiaFont->getId(); } diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index afec58dc3a360..6d87e81857f56 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -268,7 +268,7 @@ public function getLogo($useSvg = true): string { // explanation: if an SVG is requested and the app config value for logoMime is set then the logo is there. // otherwise we need to check it and maybe also generate a PNG from the SVG (that's done in getImage() which // needs to be called then) - if ($useSvg === true && $logo !== false) { + if ($useSvg === true && $logo !== null) { $logoExists = true; } else { try { diff --git a/apps/updatenotification/lib/Controller/AdminController.php b/apps/updatenotification/lib/Controller/AdminController.php index b13ba66efd573..64bdbebe37024 100644 --- a/apps/updatenotification/lib/Controller/AdminController.php +++ b/apps/updatenotification/lib/Controller/AdminController.php @@ -85,7 +85,7 @@ private function isUpdaterEnabled() { */ public function setChannel(string $channel): DataResponse { Util::setChannel($channel); - $this->config->setAppValue('core', 'lastupdatedat', 0); + $this->config->setAppValue('core', 'lastupdatedat', '0'); return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Channel updated')]]); } @@ -99,7 +99,7 @@ public function createCredentials(): DataResponse { // Create a new job and store the creation date $this->jobList->add(ResetTokenBackgroundJob::class); - $this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()); + $this->config->setAppValue('core', 'updater.secret.created', (string) $this->timeFactory->getTime()); // Create a new token $newToken = $this->secureRandom->generate(64); diff --git a/apps/updatenotification/lib/Notification/BackgroundJob.php b/apps/updatenotification/lib/Notification/BackgroundJob.php index e7dc193df6c89..58033804becc3 100644 --- a/apps/updatenotification/lib/Notification/BackgroundJob.php +++ b/apps/updatenotification/lib/Notification/BackgroundJob.php @@ -105,14 +105,14 @@ protected function checkCoreUpdate() { $status = $updater->check(); if ($status === false) { - $errors = 1 + (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0); - $this->config->setAppValue('updatenotification', 'update_check_errors', $errors); + $errors = 1 + (int) $this->config->getAppValue('updatenotification', 'update_check_errors', '0'); + $this->config->setAppValue('updatenotification', 'update_check_errors', (string) $errors); if (\in_array($errors, $this->connectionNotifications, true)) { $this->sendErrorNotifications($errors); } } elseif (\is_array($status)) { - $this->config->setAppValue('updatenotification', 'update_check_errors', 0); + $this->config->setAppValue('updatenotification', 'update_check_errors', '0'); $this->clearErrorNotifications(); if (isset($status['version'])) { @@ -186,7 +186,7 @@ protected function createNotifications($app, $version, $visibleVersion = '') { return; } - if ($lastNotification !== false) { + if ($lastNotification !== null) { // Delete old updates $this->deleteOutdatedNotifications($app, $lastNotification); } diff --git a/apps/updatenotification/lib/Notification/Notifier.php b/apps/updatenotification/lib/Notification/Notifier.php index bfbcc20348016..70453d19aee83 100644 --- a/apps/updatenotification/lib/Notification/Notifier.php +++ b/apps/updatenotification/lib/Notification/Notifier.php @@ -116,7 +116,7 @@ public function prepare(INotification $notification, string $languageCode): INot $l = $this->l10NFactory->get('updatenotification', $languageCode); if ($notification->getSubject() === 'connection_error') { - $errors = (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0); + $errors = (int) $this->config->getAppValue('updatenotification', 'update_check_errors', '0'); if ($errors === 0) { $this->notificationManager->markProcessed($notification); throw new \InvalidArgumentException('Update checked worked again'); diff --git a/apps/user_ldap/lib/User/Manager.php b/apps/user_ldap/lib/User/Manager.php index b1915ab57b5de..5a9198aeecd07 100644 --- a/apps/user_ldap/lib/User/Manager.php +++ b/apps/user_ldap/lib/User/Manager.php @@ -190,7 +190,7 @@ function ($list, $attribute) { */ public function isDeletedUser($id) { $isDeleted = $this->ocConfig->getUserValue( - $id, 'user_ldap', 'isDeleted', 0); + $id, 'user_ldap', 'isDeleted', '0'); return (int)$isDeleted === 1; } diff --git a/apps/user_ldap/lib/User/User.php b/apps/user_ldap/lib/User/User.php index 15894ce04b775..8e15abb387f8e 100644 --- a/apps/user_ldap/lib/User/User.php +++ b/apps/user_ldap/lib/User/User.php @@ -599,9 +599,9 @@ private function setOwnCloudAvatar() { * @throws \OC\ServerNotAvailableException * @throws \OCP\PreConditionNotMetException */ - public function getExtStorageHome():string { + public function getExtStorageHome(): string { $value = $this->config->getUserValue($this->getUsername(), 'user_ldap', 'extStorageHome', ''); - if ($value !== '') { + if ($value !== '' && $value !== null) { return $value; } @@ -619,7 +619,7 @@ public function getExtStorageHome():string { * @throws \OCP\PreConditionNotMetException * @throws \OC\ServerNotAvailableException */ - public function updateExtStorageHome(string $valueFromLDAP = null):string { + public function updateExtStorageHome(?string $valueFromLDAP = null): string { if ($valueFromLDAP === null) { $extHomeValues = $this->access->readAttribute($this->getDN(), $this->connection->ldapExtStorageHomeAttribute); } else { diff --git a/apps/user_ldap/lib/User_LDAP.php b/apps/user_ldap/lib/User_LDAP.php index 650c974da8173..4b00e1531d933 100644 --- a/apps/user_ldap/lib/User_LDAP.php +++ b/apps/user_ldap/lib/User_LDAP.php @@ -394,7 +394,7 @@ public function deleteUser($uid) { } } - $marked = (int)$this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0); + $marked = (int)$this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', '0'); if ($marked === 0) { try { $user = $this->access->userManager->get($uid); diff --git a/apps/weather_status/lib/Service/WeatherStatusService.php b/apps/weather_status/lib/Service/WeatherStatusService.php index fa3177b20f6f2..b3860abf8a00c 100644 --- a/apps/weather_status/lib/Service/WeatherStatusService.php +++ b/apps/weather_status/lib/Service/WeatherStatusService.php @@ -333,7 +333,7 @@ public function getLocation(): array { $lat = $this->config->getUserValue($this->userId, Application::APP_ID, 'lat', ''); $lon = $this->config->getUserValue($this->userId, Application::APP_ID, 'lon', ''); $address = $this->config->getUserValue($this->userId, Application::APP_ID, 'address', ''); - $mode = $this->config->getUserValue($this->userId, Application::APP_ID, 'mode', self::MODE_MANUAL_LOCATION); + $mode = $this->config->getUserValue($this->userId, Application::APP_ID, 'mode', (string) self::MODE_MANUAL_LOCATION); return [ 'lat' => $lat, 'lon' => $lon, diff --git a/core/Controller/WhatsNewController.php b/core/Controller/WhatsNewController.php index 12024dec03085..165450ba6960b 100644 --- a/core/Controller/WhatsNewController.php +++ b/core/Controller/WhatsNewController.php @@ -77,7 +77,7 @@ public function get():DataResponse { if ($user === null) { throw new \RuntimeException("Acting user cannot be resolved"); } - $lastRead = $this->config->getUserValue($user->getUID(), 'core', 'whatsNewLastRead', 0); + $lastRead = $this->config->getUserValue($user->getUID(), 'core', 'whatsNewLastRead', '0'); $currentVersion = $this->whatsNewService->normalizeVersion($this->config->getSystemValue('version')); if (version_compare($lastRead, $currentVersion, '>=')) { diff --git a/lib/private/AllConfig.php b/lib/private/AllConfig.php index 2a0e8f53b1494..1ae055f970c9c 100644 --- a/lib/private/AllConfig.php +++ b/lib/private/AllConfig.php @@ -1,4 +1,7 @@ connection === null) { $this->connection = \OC::$server->get(IDBConnection::class); } } /** - * Sets and deletes system wide values - * - * @param array $configs Associative array with `key => value` pairs - * If value is null, the config key will be deleted + * @inheritdoc */ - public function setSystemValues(array $configs) { + public function setSystemValues(array $configs): void { $this->systemConfig->setValues($configs); } /** - * Sets a new system wide value - * - * @param string $key the key of the value, under which will be saved - * @param mixed $value the value that should be stored + * @inheritdoc */ - public function setSystemValue($key, $value) { + public function setSystemValue(string $key, $value): void { $this->systemConfig->setValue($key, $value); } /** - * Looks up a system wide defined value - * - * @param string $key the key of the value, under which it was saved - * @param mixed $default the default value to be returned if the value isn't set - * @return mixed the value or $default + * @inheritdoc */ public function getSystemValue($key, $default = '') { return $this->systemConfig->getValue($key, $default); } /** - * Looks up a boolean system wide defined value - * - * @param string $key the key of the value, under which it was saved - * @param bool $default the default value to be returned if the value isn't set - * - * @return bool - * - * @since 16.0.0 + * @inheritdoc */ public function getSystemValueBool(string $key, bool $default = false): bool { return (bool) $this->getSystemValue($key, $default); } /** - * Looks up an integer system wide defined value - * - * @param string $key the key of the value, under which it was saved - * @param int $default the default value to be returned if the value isn't set - * - * @return int - * - * @since 16.0.0 + * @inheritdoc */ public function getSystemValueInt(string $key, int $default = 0): int { return (int) $this->getSystemValue($key, $default); } /** - * Looks up a string system wide defined value - * - * @param string $key the key of the value, under which it was saved - * @param string $default the default value to be returned if the value isn't set - * - * @return string - * - * @since 16.0.0 + * @inheritdoc */ public function getSystemValueString(string $key, string $default = ''): string { return (string) $this->getSystemValue($key, $default); } /** - * Looks up a system wide defined value and filters out sensitive data - * - * @param string $key the key of the value, under which it was saved - * @param mixed $default the default value to be returned if the value isn't set - * @return mixed the value or $default + * @inheritdoc */ - public function getFilteredSystemValue($key, $default = '') { + public function getFilteredSystemValue(string $key, string $default = ''): string { return $this->systemConfig->getFilteredValue($key, $default); } /** - * Delete a system wide defined value - * - * @param string $key the key of the value, under which it was saved + * @inheritdoc */ - public function deleteSystemValue($key) { + public function deleteSystemValue(string $key): void { $this->systemConfig->deleteValue($key); } /** - * Get all keys stored for an app - * - * @param string $appName the appName that we stored the value under - * @return string[] the keys stored for the app + * @inheritdoc */ - public function getAppKeys($appName) { + public function getAppKeys(string $appName): array { return \OC::$server->get(AppConfig::class)->getKeys($appName); } /** - * Writes a new app wide value - * - * @param string $appName the appName that we want to store the value under - * @param string $key the key of the value, under which will be saved - * @param string|float|int $value the value that should be stored + * @inheritdoc */ - public function setAppValue($appName, $key, $value) { + public function setAppValue(string $appName, string $key, string $value): void { \OC::$server->get(AppConfig::class)->setValue($appName, $key, $value); } /** - * Looks up an app wide defined value - * - * @param string $appName the appName that we stored the value under - * @param string $key the key of the value, under which it was saved - * @param string $default the default value to be returned if the value isn't set - * @return string the saved value + * @inheritdoc */ - public function getAppValue($appName, $key, $default = '') { + public function getAppValue(string $appName, string $key, $default = '') { return \OC::$server->get(AppConfig::class)->getValue($appName, $key, $default); } /** - * Delete an app wide defined value - * - * @param string $appName the appName that we stored the value under - * @param string $key the key of the value, under which it was saved + * @inheritdoc */ - public function deleteAppValue($appName, $key) { + public function deleteAppValue(string $appName, string $key): void { \OC::$server->get(AppConfig::class)->deleteKey($appName, $key); } /** - * Removes all keys in appconfig belonging to the app - * - * @param string $appName the appName the configs are stored under + * @inheritdoc */ - public function deleteAppValues($appName) { + public function deleteAppValues(string $appName): void { \OC::$server->get(AppConfig::class)->deleteApp($appName); } - /** - * Set a user defined value - * - * @param string $userId the userId of the user that we want to store the value under - * @param string $appName the appName that we want to store the value under - * @param string $key the key under which the value is being stored - * @param string|float|int $value the value that you want to store - * @param string $preCondition only update if the config value was previously the value passed as $preCondition - * @throws \OCP\PreConditionNotMetException if a precondition is specified and is not met - * @throws \UnexpectedValueException when trying to store an unexpected value + * @inheritdoc */ - public function setUserValue($userId, $appName, $key, $value, $preCondition = null) { - if (!is_int($value) && !is_float($value) && !is_string($value)) { - throw new \UnexpectedValueException('Only integers, floats and strings are allowed as value'); - } - + public function setUserValue(string $userId, string $appName, string $key, string $value, ?string $preCondition = null): void { // TODO - FIXME $this->fixDIInit(); if ($appName === 'settings' && $key === 'email') { - $value = strtolower((string) $value); + $value = strtolower($value); } $prevValue = $this->getUserValue($userId, $appName, $key, null); if ($prevValue !== null) { - if ($prevValue === (string)$value) { + if ($prevValue === $value) { return; } elseif ($preCondition !== null && $prevValue !== (string)$preCondition) { throw new PreConditionNotMetException(); @@ -306,15 +242,9 @@ public function setUserValue($userId, $appName, $key, $value, $preCondition = nu } /** - * Getting a user defined value - * - * @param ?string $userId the userId of the user that we want to store the value under - * @param string $appName the appName that we stored the value under - * @param string $key the key under which the value is being stored - * @param mixed $default the default value to be returned if the value isn't set - * @return string + * @inheritdoc */ - public function getUserValue($userId, $appName, $key, $default = '') { + public function getUserValue(?string $userId, string $appName, string $key, ?string $default = ''): ?string { $data = $this->getAllUserValues($userId); if (isset($data[$appName][$key])) { return $data[$appName][$key]; @@ -324,13 +254,9 @@ public function getUserValue($userId, $appName, $key, $default = '') { } /** - * Get the keys of all stored by an app for the user - * - * @param string $userId the userId of the user that we want to store the value under - * @param string $appName the appName that we stored the value under - * @return string[] + * @inheritdoc */ - public function getUserKeys($userId, $appName) { + public function getUserKeys(?string $userId, string $appName): array { $data = $this->getAllUserValues($userId); if (isset($data[$appName])) { return array_keys($data[$appName]); @@ -340,13 +266,9 @@ public function getUserKeys($userId, $appName) { } /** - * Delete a user value - * - * @param string $userId the userId of the user that we want to store the value under - * @param string $appName the appName that we stored the value under - * @param string $key the key under which the value is being stored + * @inheritdoc */ - public function deleteUserValue($userId, $appName, $key) { + public function deleteUserValue(string $userId, string $appName, string $key): void { // TODO - FIXME $this->fixDIInit(); @@ -363,11 +285,9 @@ public function deleteUserValue($userId, $appName, $key) { } /** - * Delete all user values - * - * @param string $userId the userId of the user that we want to remove all values from + * @inheritdoc */ - public function deleteAllUserValues($userId) { + public function deleteAllUserValues(string $userId): void { // TODO - FIXME $this->fixDIInit(); $qb = $this->connection->getQueryBuilder(); @@ -379,11 +299,9 @@ public function deleteAllUserValues($userId) { } /** - * Delete all user related values of one app - * - * @param string $appName the appName of the app that we want to remove all values from + * @inheritdoc */ - public function deleteAppFromAllUsers($appName) { + public function deleteAppFromAllUsers(string $appName): void { // TODO - FIXME $this->fixDIInit(); @@ -398,14 +316,7 @@ public function deleteAppFromAllUsers($appName) { } /** - * Returns all user configs sorted by app of one user - * - * @param ?string $userId the user ID to get the app configs from - * @psalm-return array> - * @return array[] - 2 dimensional array with the following structure: - * [ $appId => - * [ $key => $value ] - * ] + * @inheritdoc */ public function getAllUserValues(?string $userId): array { if (isset($this->userCache[$userId])) { @@ -438,18 +349,13 @@ public function getAllUserValues(?string $userId): array { } /** - * Fetches a mapped list of userId -> value, for a specified app and key and a list of user IDs. - * - * @param string $appName app to get the value for - * @param string $key the key to get the value for - * @param array $userIds the user IDs to fetch the values for - * @return array Mapped values: userId => value + * @inheritdoc */ - public function getUserValueForUsers($appName, $key, $userIds) { + public function getUserValueForUsers(string $appName, string $key, array $userIds): array { // TODO - FIXME $this->fixDIInit(); - if (empty($userIds) || !is_array($userIds)) { + if (empty($userIds)) { return []; } @@ -478,14 +384,9 @@ public function getUserValueForUsers($appName, $key, $userIds) { } /** - * Determines the users that have the given value set for a specific app-key-pair - * - * @param string $appName the app to get the user for - * @param string $key the key to get the user for - * @param string $value the value to get the user for - * @return array of user IDs + * @inheritdoc */ - public function getUsersForUserValue($appName, $key, $value) { + public function getUsersForUserValue(string $appName, string $key, string $value): array { // TODO - FIXME $this->fixDIInit(); @@ -509,14 +410,9 @@ public function getUsersForUserValue($appName, $key, $value) { } /** - * Determines the users that have the given value set for a specific app-key-pair - * - * @param string $appName the app to get the user for - * @param string $key the key to get the user for - * @param string $value the value to get the user for - * @return array of user IDs + * @inheritdoc */ - public function getUsersForUserValueCaseInsensitive($appName, $key, $value) { + public function getUsersForUserValueCaseInsensitive(string $appName, string $key, string $value): array { // TODO - FIXME $this->fixDIInit(); diff --git a/lib/private/AppConfig.php b/lib/private/AppConfig.php index 708b31b313671..6dbb27165b220 100644 --- a/lib/private/AppConfig.php +++ b/lib/private/AppConfig.php @@ -1,4 +1,7 @@ * @copyright Copyright (c) 2016, ownCloud, Inc. @@ -44,7 +47,7 @@ class AppConfig implements IAppConfig { /** @var array[] */ - protected $sensitiveValues = [ + protected const SENSITIVE_VALUES = [ 'circles' => [ '/^key_pairs$/', '/^local_gskey$/', @@ -158,7 +161,7 @@ public function __construct(Connection $conn) { * @param string $app * @return array */ - private function getAppValues($app) { + private function getAppValues(string $app): array { $this->loadConfigValues(); if (isset($this->cache[$app])) { @@ -169,14 +172,9 @@ private function getAppValues($app) { } /** - * Get all apps using the config - * - * @return array an array of app ids - * - * This function returns a list of all apps that have at least one - * entry in the appconfig table. + * @inheritdoc */ - public function getApps() { + public function getApps(): array { $this->loadConfigValues(); return $this->getSortedKeys($this->cache); @@ -191,7 +189,7 @@ public function getApps() { * This function gets all keys of an app. Please note that the values are * not returned. */ - public function getKeys($app) { + public function getKeys(string $app): array { $this->loadConfigValues(); if (isset($this->cache[$app])) { @@ -201,7 +199,7 @@ public function getKeys($app) { return []; } - public function getSortedKeys($data) { + public function getSortedKeys(array $data): array { $keys = array_keys($data); sort($keys); return $keys; @@ -218,7 +216,7 @@ public function getSortedKeys($data) { * This function gets a value from the appconfig table. If the key does * not exist the default value will be returned */ - public function getValue($app, $key, $default = null) { + public function getValue(string $app, string $key, ?string $default = null): ?string { $this->loadConfigValues(); if ($this->hasKey($app, $key)) { @@ -229,13 +227,9 @@ public function getValue($app, $key, $default = null) { } /** - * check if a key is set in the appconfig - * - * @param string $app - * @param string $key - * @return bool + * @inheritdoc */ - public function hasKey($app, $key) { + public function hasKey(string $app, string $key): bool { $this->loadConfigValues(); return isset($this->cache[$app][$key]); @@ -249,7 +243,7 @@ public function hasKey($app, $key) { * @param string|float|int $value value * @return bool True if the value was inserted or updated, false if the value was the same */ - public function setValue($app, $key, $value) { + public function setValue(string $app, string $key, $value): bool { if (!$this->hasKey($app, $key)) { $inserted = (bool) $this->conn->insertIfNotExist('*PREFIX*appconfig', [ 'appid' => $app, @@ -317,7 +311,7 @@ public function setValue($app, $key, $value) { * @param string $key key * @return boolean */ - public function deleteKey($app, $key) { + public function deleteKey(string $app, string $key): bool { $this->loadConfigValues(); $sql = $this->conn->getQueryBuilder(); @@ -340,7 +334,7 @@ public function deleteKey($app, $key) { * * Removes all keys in appconfig belonging to the app. */ - public function deleteApp($app) { + public function deleteApp(string $app): bool { $this->loadConfigValues(); $sql = $this->conn->getQueryBuilder(); @@ -354,11 +348,7 @@ public function deleteApp($app) { } /** - * get multiple values, either the app or key can be used as wildcard by setting it to false - * - * @param string|false $app - * @param string|false $key - * @return array|false + * @inheritdoc */ public function getValues($app, $key) { if (($app !== false) === ($key !== false)) { @@ -379,16 +369,13 @@ public function getValues($app, $key) { } /** - * get all values of the app or and filters out sensitive data - * - * @param string $app - * @return array + * @inheritdoc */ - public function getFilteredValues($app) { + public function getFilteredValues(string $app): array { $values = $this->getValues($app, false); - if (isset($this->sensitiveValues[$app])) { - foreach ($this->sensitiveValues[$app] as $sensitiveKeyExp) { + if (isset(self::SENSITIVE_VALUES[$app])) { + foreach (self::SENSITIVE_VALUES[$app] as $sensitiveKeyExp) { $sensitiveKeys = preg_grep($sensitiveKeyExp, array_keys($values)); foreach ($sensitiveKeys as $sensitiveKey) { $values[$sensitiveKey] = IConfig::SENSITIVE_VALUE; @@ -402,7 +389,7 @@ public function getFilteredValues($app) { /** * Load all the app config values */ - protected function loadConfigValues() { + protected function loadConfigValues(): void { if ($this->configLoaded) { return; } diff --git a/lib/private/AppFramework/Services/AppConfig.php b/lib/private/AppFramework/Services/AppConfig.php index 355a41239875e..adf421d01d599 100644 --- a/lib/private/AppFramework/Services/AppConfig.php +++ b/lib/private/AppFramework/Services/AppConfig.php @@ -66,7 +66,7 @@ public function setUserValue(string $userId, string $key, string $value, ?string $this->config->setUserValue($userId, $this->appName, $key, $value, $preCondition); } - public function getUserValue(string $userId, string $key, string $default = ''): string { + public function getUserValue(string $userId, string $key, string $default = ''): ?string { return $this->config->getUserValue($userId, $this->appName, $key, $default); } diff --git a/lib/private/Authentication/TwoFactorAuth/Manager.php b/lib/private/Authentication/TwoFactorAuth/Manager.php index 37a9f03d07383..45cdb6d46b560 100644 --- a/lib/private/Authentication/TwoFactorAuth/Manager.php +++ b/lib/private/Authentication/TwoFactorAuth/Manager.php @@ -279,7 +279,7 @@ public function verifyChallenge(string $providerId, IUser $user, string $challen $sessionId = $this->session->getId(); $token = $this->tokenProvider->getToken($sessionId); $tokenId = $token->getId(); - $this->config->deleteUserValue($user->getUID(), 'login_token_2fa', $tokenId); + $this->config->deleteUserValue($user->getUID(), 'login_token_2fa', (string)$tokenId); $dispatchEvent = new GenericEvent($user, ['provider' => $provider->getDisplayName()]); $this->legacyDispatcher->dispatch(IProvider::EVENT_SUCCESS, $dispatchEvent); @@ -395,7 +395,7 @@ public function prepareTwoFactorLogin(IUser $user, bool $rememberMe) { $id = $this->session->getId(); $token = $this->tokenProvider->getToken($id); - $this->config->setUserValue($user->getUID(), 'login_token_2fa', (string) $token->getId(), $this->timeFactory->getTime()); + $this->config->setUserValue($user->getUID(), 'login_token_2fa', (string) $token->getId(), (string) $this->timeFactory->getTime()); } public function clearTwoFactorPending(string $userId) { diff --git a/lib/private/Console/TimestampFormatter.php b/lib/private/Console/TimestampFormatter.php index c25ed578805af..e5a84a558ebee 100644 --- a/lib/private/Console/TimestampFormatter.php +++ b/lib/private/Console/TimestampFormatter.php @@ -94,7 +94,7 @@ public function getStyle($name) { /** * Formats a message according to the given styles. * - * @param string $message The message to style + * @param ?string $message The message to style * @return string The styled message, prepended with a timestamp using the * log timezone and dateformat, e.g. "2015-06-23T17:24:37+02:00" */ diff --git a/lib/private/Template/JSConfigHelper.php b/lib/private/Template/JSConfigHelper.php index 7b6d0a6a34648..e67a71ac6110c 100644 --- a/lib/private/Template/JSConfigHelper.php +++ b/lib/private/Template/JSConfigHelper.php @@ -287,7 +287,7 @@ public function getConfig(): string { if ($this->currentUser !== null) { $array['oc_userconfig'] = json_encode([ 'avatar' => [ - 'version' => (int)$this->config->getUserValue($uid, 'avatar', 'version', 0), + 'version' => (int)$this->config->getUserValue($uid, 'avatar', 'version', '0'), 'generated' => $this->config->getUserValue($uid, 'avatar', 'generated', 'true') === 'true', ] ]); diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index e043f79745ac0..0d60545c7b7b2 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -154,7 +154,7 @@ public function __construct($renderAs, $appId = '') { $this->assign('userStatus', false); } else { $this->assign('userAvatarSet', true); - $this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0)); + $this->assign('userAvatarVersion', $this->config->getUserValue(\OC_User::getUser(), 'avatar', 'version', '0')); } } elseif ($renderAs === TemplateResponse::RENDER_AS_ERROR) { parent::__construct('core', 'layout.guest', '', false); diff --git a/lib/private/User/User.php b/lib/private/User/User.php index eda6b5f79d946..276fcc94ea1bc 100644 --- a/lib/private/User/User.php +++ b/lib/private/User/User.php @@ -238,7 +238,7 @@ private function ensureAccountManager() { */ public function getLastLogin() { if ($this->lastLogin === null) { - $this->lastLogin = (int) $this->config->getUserValue($this->uid, 'login', 'lastLogin', 0); + $this->lastLogin = (int) $this->config->getUserValue($this->uid, 'login', 'lastLogin', '0'); } return (int) $this->lastLogin; } diff --git a/lib/public/AppFramework/Services/IAppConfig.php b/lib/public/AppFramework/Services/IAppConfig.php index baac2946e3c39..705a518b7299f 100644 --- a/lib/public/AppFramework/Services/IAppConfig.php +++ b/lib/public/AppFramework/Services/IAppConfig.php @@ -94,11 +94,11 @@ public function setUserValue(string $userId, string $key, string $value, ?string * * @param string $userId the userId of the user that we want to store the value under * @param string $key the key under which the value is being stored - * @param mixed $default the default value to be returned if the value isn't set - * @return string + * @param string $default the default value to be returned if the value isn't set + * @return ?string * @since 20.0.0 */ - public function getUserValue(string $userId, string $key, string $default = ''): string; + public function getUserValue(string $userId, string $key, string $default = ''): ?string; /** * Delete a user value diff --git a/lib/public/IAppConfig.php b/lib/public/IAppConfig.php index 7ab70fb04bfb4..3b5e7dafc7373 100644 --- a/lib/public/IAppConfig.php +++ b/lib/public/IAppConfig.php @@ -1,4 +1,7 @@ value, for a specified app and key and a list of user IDs. @@ -204,22 +208,22 @@ public function getUserValue($userId, $appName, $key, $default = ''); * @return array Mapped values: userId => value * @since 8.0.0 */ - public function getUserValueForUsers($appName, $key, $userIds); + public function getUserValueForUsers(string $appName, string $key, array $userIds): array; /** * Get the keys of all stored by an app for the user * - * @param string $userId the userId of the user that we want to store the value under + * @param ?string $userId the userId of the user that we want to store the value under * @param string $appName the appName that we stored the value under * @return string[] * @since 8.0.0 */ - public function getUserKeys($userId, $appName); + public function getUserKeys(?string $userId, string $appName): array; /** * Get all user configs sorted by app of one user * - * @param string $userId the userId of the user that we want to get all values from + * @param ?string $userId the userId of the user that we want to get all values from * @psalm-return array> * @return array[] - 2 dimensional array with the following structure: * [ $appId => @@ -227,7 +231,7 @@ public function getUserKeys($userId, $appName); * ] * @since 24.0.0 */ - public function getAllUserValues(string $userId): array; + public function getAllUserValues(?string $userId): array; /** * Delete a user value @@ -237,7 +241,7 @@ public function getAllUserValues(string $userId): array; * @param string $key the key under which the value is being stored * @since 8.0.0 */ - public function deleteUserValue($userId, $appName, $key); + public function deleteUserValue(string $userId, string $appName, string $key): void; /** * Delete all user values @@ -245,7 +249,7 @@ public function deleteUserValue($userId, $appName, $key); * @param string $userId the userId of the user that we want to remove all values from * @since 8.0.0 */ - public function deleteAllUserValues($userId); + public function deleteAllUserValues(string $userId): void; /** * Delete all user related values of one app @@ -253,7 +257,7 @@ public function deleteAllUserValues($userId); * @param string $appName the appName of the app that we want to remove all values from * @since 8.0.0 */ - public function deleteAppFromAllUsers($appName); + public function deleteAppFromAllUsers(string $appName): void; /** * Determines the users that have the given value set for a specific app-key-pair @@ -264,5 +268,5 @@ public function deleteAppFromAllUsers($appName); * @return array of user IDs * @since 8.0.0 */ - public function getUsersForUserValue($appName, $key, $value); + public function getUsersForUserValue(string $appName, string $key, string $value): array; }