refactor(updatenotification): add return types and fix typos

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
pull/52669/head
Ferdinand Thiessen 5 months ago
parent ff318138a2
commit 6e9b4eb0a8
No known key found for this signature in database
GPG Key ID: 45FAE7268762B400
  1. 12
      apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php
  2. 16
      apps/updatenotification/lib/Command/Check.php
  3. 5
      apps/updatenotification/lib/Controller/AdminController.php
  4. 2
      apps/updatenotification/lib/Manager.php
  5. 13
      apps/updatenotification/lib/Notification/Notifier.php
  6. 1
      apps/updatenotification/lib/UpdateChecker.php
  7. 11
      apps/updatenotification/tests/Notification/NotifierTest.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)

@ -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 {

@ -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');
}
/**

@ -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 {

@ -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();
}

@ -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;

@ -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,

Loading…
Cancel
Save