From a03c8dc70a711a40bbf05879cfe46d4939537d67 Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Wed, 28 Oct 2026 15:34:29 +0100 Subject: [PATCH] fix(lock): only return string app names from getAppName A localized in info.xml makes getAppInfo() return an array, which threw a TypeError on the ?string return type. Drop the misleading psalm annotation and only return string names. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Julius Knorr --- lib/Service/LockService.php | 4 +- tests/Unit/Service/LockServiceTest.php | 60 ++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 tests/Unit/Service/LockServiceTest.php diff --git a/lib/Service/LockService.php b/lib/Service/LockService.php index 31f60360..9f508564 100644 --- a/lib/Service/LockService.php +++ b/lib/Service/LockService.php @@ -174,9 +174,9 @@ public function update(FileLock $lock): void { } public function getAppName(string $appId): ?string { - /** @var array{name: null}|null $appInfo */ $appInfo = $this->appManager->getAppInfo($appId); - return $appInfo['name'] ?? null; + $name = $appInfo['name'] ?? null; + return is_string($name) ? $name : null; } /** diff --git a/tests/Unit/Service/LockServiceTest.php b/tests/Unit/Service/LockServiceTest.php new file mode 100644 index 00000000..a0143d20 --- /dev/null +++ b/tests/Unit/Service/LockServiceTest.php @@ -0,0 +1,60 @@ +createMock(IAppManager::class); + $appManager->method('getAppInfo')->with('richdocuments')->willReturn($appInfo); + + $service = new LockService( + $this->createMock(IL10N::class), + $this->createMock(IUserManager::class), + $this->createMock(LocksRequest::class), + $this->createMock(FileService::class), + $this->createMock(IAppConfig::class), + $appManager, + $this->createMock(IEventDispatcher::class), + $this->createMock(IUserSession::class), + $this->createMock(IRequest::class), + $this->createMock(LoggerInterface::class), + $this->createMock(IRootFolder::class), + ); + + $this->assertSame($expected, $service->getAppName('richdocuments')); + } + + public static function appInfoProvider(): array { + return [ + 'name' => [['name' => 'Nextcloud Office'], 'Nextcloud Office'], + 'missing app' => [null, null], + 'no name' => [[], null], + 'untranslated name' => [['name' => [['@value' => 'Nextcloud Office']]], null], + ]; + } +}