Skip to content

Commit 9255afa

Browse files
committed
refactor(updatenotification): use consistant patterns for on-demand class members
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent be3cf85 commit 9255afa

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

apps/updatenotification/lib/Controller/APIController.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
*/
2727
class APIController extends OCSController {
2828

29-
/** @var string */
30-
protected $language;
29+
protected ?string $language = null;
3130

3231
/**
3332
* List of apps that were in the appstore but are now shipped and don't have
@@ -95,7 +94,7 @@ public function getAppList(string $newVersion): DataResponse {
9594
$this->appFetcher->setVersion($newVersion, 'future-apps.json', false);
9695

9796
// Apps available on the app store for that version
98-
$availableApps = array_map(static function (array $app) {
97+
$availableApps = array_map(static function (array $app): string {
9998
return $app['id'];
10099
}, $this->appFetcher->get());
101100

@@ -106,8 +105,6 @@ public function getAppList(string $newVersion): DataResponse {
106105
], Http::STATUS_NOT_FOUND);
107106
}
108107

109-
$this->language = $this->l10nFactory->getUserLanguage($this->userSession->getUser());
110-
111108
// Ignore apps that are deployed from git
112109
$installedApps = array_filter($installedApps, function (string $appId) {
113110
try {
@@ -139,14 +136,20 @@ public function getAppList(string $newVersion): DataResponse {
139136
*/
140137
protected function getAppDetails(string $appId): array {
141138
$app = $this->appManager->getAppInfo($appId, false, $this->language);
142-
/** @var ?string $name */
143-
$name = $app['name'];
139+
$name = $app['name'] ?? $appId;
144140
return [
145141
'appId' => $appId,
146-
'appName' => $name ?? $appId,
142+
'appName' => $name,
147143
];
148144
}
149145

146+
protected function getLanguage(): string {
147+
if ($this->language === null) {
148+
$this->language = $this->l10nFactory->getUserLanguage($this->userSession->getUser());
149+
}
150+
return $this->language;
151+
}
152+
150153
/**
151154
* Get changelog entry for an app
152155
*

0 commit comments

Comments
 (0)