From 9255afaeab82beaf46f5ed7a6b7dc5caef7c3f45 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Tue, 6 May 2025 19:43:57 +0200 Subject: [PATCH] refactor(updatenotification): use consistant patterns for on-demand class members Signed-off-by: Ferdinand Thiessen --- .../lib/Controller/APIController.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/apps/updatenotification/lib/Controller/APIController.php b/apps/updatenotification/lib/Controller/APIController.php index c96a5101e0f..4360d814dd2 100644 --- a/apps/updatenotification/lib/Controller/APIController.php +++ b/apps/updatenotification/lib/Controller/APIController.php @@ -26,8 +26,7 @@ use OCP\L10N\IFactory; */ class APIController extends OCSController { - /** @var string */ - protected $language; + protected ?string $language = null; /** * List of apps that were in the appstore but are now shipped and don't have @@ -95,7 +94,7 @@ class APIController extends OCSController { $this->appFetcher->setVersion($newVersion, 'future-apps.json', false); // Apps available on the app store for that version - $availableApps = array_map(static function (array $app) { + $availableApps = array_map(static function (array $app): string { return $app['id']; }, $this->appFetcher->get()); @@ -106,8 +105,6 @@ class APIController extends OCSController { ], Http::STATUS_NOT_FOUND); } - $this->language = $this->l10nFactory->getUserLanguage($this->userSession->getUser()); - // Ignore apps that are deployed from git $installedApps = array_filter($installedApps, function (string $appId) { try { @@ -139,14 +136,20 @@ class APIController extends OCSController { */ protected function getAppDetails(string $appId): array { $app = $this->appManager->getAppInfo($appId, false, $this->language); - /** @var ?string $name */ - $name = $app['name']; + $name = $app['name'] ?? $appId; return [ 'appId' => $appId, - 'appName' => $name ?? $appId, + 'appName' => $name, ]; } + protected function getLanguage(): string { + if ($this->language === null) { + $this->language = $this->l10nFactory->getUserLanguage($this->userSession->getUser()); + } + return $this->language; + } + /** * Get changelog entry for an app *