From 6e9b4eb0a8bf8ea6729bb82df0faca8914799f6e Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Tue, 6 May 2025 19:41:22 +0200 Subject: [PATCH] refactor(updatenotification): add return types and fix typos Signed-off-by: Ferdinand Thiessen --- .../UpdateAvailableNotifications.php | 12 ++++++------ apps/updatenotification/lib/Command/Check.php | 16 ++-------------- .../lib/Controller/AdminController.php | 5 +++-- apps/updatenotification/lib/Manager.php | 2 +- .../lib/Notification/Notifier.php | 13 +++---------- apps/updatenotification/lib/UpdateChecker.php | 1 + .../tests/Notification/NotifierTest.php | 11 ++++++----- 7 files changed, 22 insertions(+), 38 deletions(-) diff --git a/apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php b/apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php index 917297bacb7..49b5a44b85d 100644 --- a/apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php +++ b/apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php @@ -67,7 +67,7 @@ class UpdateAvailableNotifications extends TimedJob { /** * Check for Nextcloud server update */ - protected function checkCoreUpdate() { + protected function checkCoreUpdate(): void { if (!$this->config->getSystemValueBool('updatechecker', true)) { // update checker is disabled so no core update check! return; @@ -100,7 +100,7 @@ class UpdateAvailableNotifications extends TimedJob { * Send a message to the admin when the update server could not be reached * @param int $numDays */ - protected function sendErrorNotifications($numDays) { + protected function sendErrorNotifications($numDays): void { $this->clearErrorNotifications(); $notification = $this->notificationManager->createNotification(); @@ -122,7 +122,7 @@ class UpdateAvailableNotifications extends TimedJob { /** * Remove error notifications again */ - protected function clearErrorNotifications() { + protected function clearErrorNotifications(): void { $notification = $this->notificationManager->createNotification(); try { $notification->setApp(Application::APP_NAME) @@ -137,7 +137,7 @@ class UpdateAvailableNotifications extends TimedJob { /** * Check all installed apps for updates */ - protected function checkAppUpdates() { + protected function checkAppUpdates(): void { $apps = $this->appManager->getEnabledApps(); foreach ($apps as $app) { $update = $this->isUpdateAvailable($app); @@ -154,7 +154,7 @@ class UpdateAvailableNotifications extends TimedJob { * @param string $version * @param string $visibleVersion */ - protected function createNotifications($app, $version, $visibleVersion = '') { + protected function createNotifications($app, $version, $visibleVersion = ''): void { $lastNotification = $this->appConfig->getAppValueString($app, ''); if ($lastNotification === $version) { // We already notified about this update @@ -218,7 +218,7 @@ class UpdateAvailableNotifications extends TimedJob { * @param string $app * @param string $version */ - protected function deleteOutdatedNotifications($app, $version) { + protected function deleteOutdatedNotifications($app, $version): void { $notification = $this->notificationManager->createNotification(); try { $notification->setApp(Application::APP_NAME) diff --git a/apps/updatenotification/lib/Command/Check.php b/apps/updatenotification/lib/Command/Check.php index c7de570cd2c..d93e4935012 100644 --- a/apps/updatenotification/lib/Command/Check.php +++ b/apps/updatenotification/lib/Command/Check.php @@ -17,24 +17,12 @@ use Symfony\Component\Console\Output\OutputInterface; class Check extends Command { - /** - * @var Installer $installer - */ - private $installer; - - /** - * @var AppManager $appManager - */ - private $appManager; - public function __construct( - AppManager $appManager, + private AppManager $appManager, private UpdateChecker $updateChecker, - Installer $installer, + private Installer $installer, ) { parent::__construct(); - $this->installer = $installer; - $this->appManager = $appManager; } protected function configure(): void { diff --git a/apps/updatenotification/lib/Controller/AdminController.php b/apps/updatenotification/lib/Controller/AdminController.php index 6e7f9935d93..26745948890 100644 --- a/apps/updatenotification/lib/Controller/AdminController.php +++ b/apps/updatenotification/lib/Controller/AdminController.php @@ -4,6 +4,7 @@ declare(strict_types=1); /** * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-only */ namespace OCA\UpdateNotification\Controller; @@ -36,8 +37,8 @@ class AdminController extends Controller { parent::__construct($appName, $request); } - private function isUpdaterEnabled() { - return !$this->config->getSystemValue('upgrade.disable-web', false); + private function isUpdaterEnabled(): bool { + return !$this->config->getSystemValueBool('upgrade.disable-web'); } /** diff --git a/apps/updatenotification/lib/Manager.php b/apps/updatenotification/lib/Manager.php index b6f455f93fe..ebc1c83a9b4 100644 --- a/apps/updatenotification/lib/Manager.php +++ b/apps/updatenotification/lib/Manager.php @@ -73,7 +73,7 @@ class Manager { /** * Retrieve a log entry from the changelog - * @param string $path The path to the changlog file + * @param string $path The path to the changelog file * @param string $version The version to query (make sure to only pass in "{major}.{minor}(.{patch}" format) */ protected function retrieveChangelogEntry(string $path, string $version): ?string { diff --git a/apps/updatenotification/lib/Notification/Notifier.php b/apps/updatenotification/lib/Notification/Notifier.php index ce56e875163..787675bd98d 100644 --- a/apps/updatenotification/lib/Notification/Notifier.php +++ b/apps/updatenotification/lib/Notification/Notifier.php @@ -10,7 +10,7 @@ namespace OCA\UpdateNotification\Notification; use OCA\UpdateNotification\AppInfo\Application; use OCP\App\IAppManager; -use OCP\IConfig; +use OCP\AppFramework\Services\IAppConfig; use OCP\IGroupManager; use OCP\IURLGenerator; use OCP\IUser; @@ -29,17 +29,10 @@ class Notifier implements INotifier { /** * Notifier constructor. - * - * @param IURLGenerator $url - * @param IConfig $config - * @param IManager $notificationManager - * @param IFactory $l10NFactory - * @param IUserSession $userSession - * @param IGroupManager $groupManager */ public function __construct( protected IURLGenerator $url, - protected IConfig $config, + protected IAppConfig $appConfig, protected IManager $notificationManager, protected IFactory $l10NFactory, protected IUserSession $userSession, @@ -89,7 +82,7 @@ class Notifier implements INotifier { $l = $this->l10NFactory->get(Application::APP_NAME, $languageCode); if ($notification->getSubject() === 'connection_error') { - $errors = $this->appConfig->getValueInt(Application::APP_NAME, 'update_check_errors', 0); + $errors = $this->appConfig->getAppValueInt('update_check_errors', 0); if ($errors === 0) { throw new AlreadyProcessedException(); } diff --git a/apps/updatenotification/lib/UpdateChecker.php b/apps/updatenotification/lib/UpdateChecker.php index 76afc8f6a54..b206ba4a3e4 100644 --- a/apps/updatenotification/lib/UpdateChecker.php +++ b/apps/updatenotification/lib/UpdateChecker.php @@ -4,6 +4,7 @@ declare(strict_types=1); /** * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-only */ namespace OCA\UpdateNotification; diff --git a/apps/updatenotification/tests/Notification/NotifierTest.php b/apps/updatenotification/tests/Notification/NotifierTest.php index 45c4fc9960f..4102fdcb773 100644 --- a/apps/updatenotification/tests/Notification/NotifierTest.php +++ b/apps/updatenotification/tests/Notification/NotifierTest.php @@ -4,13 +4,14 @@ declare(strict_types=1); /** * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-only */ namespace OCA\UpdateNotification\Tests\Notification; use OCA\UpdateNotification\Notification\Notifier; use OCP\App\IAppManager; -use OCP\IConfig; +use OCP\AppFramework\Services\IAppConfig; use OCP\IGroupManager; use OCP\IURLGenerator; use OCP\IUserSession; @@ -25,7 +26,7 @@ use Test\TestCase; class NotifierTest extends TestCase { protected IURLGenerator&MockObject $urlGenerator; - protected IConfig&MockObject $config; + protected IAppConfig&MockObject $appConfig; protected IManager&MockObject $notificationManager; protected IFactory&MockObject $l10nFactory; protected IUserSession&MockObject $userSession; @@ -37,7 +38,7 @@ class NotifierTest extends TestCase { parent::setUp(); $this->urlGenerator = $this->createMock(IURLGenerator::class); - $this->config = $this->createMock(IConfig::class); + $this->appConfig = $this->createMock(IAppConfig::class); $this->notificationManager = $this->createMock(IManager::class); $this->l10nFactory = $this->createMock(IFactory::class); $this->userSession = $this->createMock(IUserSession::class); @@ -54,7 +55,7 @@ class NotifierTest extends TestCase { if (empty($methods)) { return new Notifier( $this->urlGenerator, - $this->config, + $this->appConfig, $this->notificationManager, $this->l10nFactory, $this->userSession, @@ -67,7 +68,7 @@ class NotifierTest extends TestCase { return $this->getMockBuilder(Notifier::class) ->setConstructorArgs([ $this->urlGenerator, - $this->config, + $this->appConfig, $this->notificationManager, $this->l10nFactory, $this->userSession,