Skip to content

Commit b2b572e

Browse files
szaimenclaude
andcommitted
fix(psalm): Resolve static analysis errors for ExApp backend
- Classifier: generator return type void -> null (bare return yields null) - AdminController: avoid RiskyTruthyFalsyComparison via explicit (bool) cast - ExAppService: mark final; suppress Mixed* from the optional AppAPI PublicFunctions calls (UndefinedClass dependency) and cast the error message operand to string Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent dfef072 commit b2b572e

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

lib/Classifiers/Classifier.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public function classifyFiles(string $model, array $queueFiles, int $timeout): \
203203
* @param int $timeout
204204
* @param int $startTime
205205
* @return \Generator
206-
* @psalm-return \Generator<int, string, mixed, void>
206+
* @psalm-return \Generator<int, string, mixed, null>
207207
* @throws \ErrorException|\RuntimeException
208208
*/
209209
private function runLocally(string $model, array $paths, int $timeout, int $startTime): \Generator {
@@ -297,7 +297,7 @@ private function runLocally(string $model, array $paths, int $timeout, int $star
297297
* @param list<string> $paths
298298
* @param int $timeout
299299
* @return \Generator
300-
* @psalm-return \Generator<int, string, mixed, void>
300+
* @psalm-return \Generator<int, string, mixed, null>
301301
* @throws \ErrorException
302302
*/
303303
private function runExApp(string $model, array $paths, int $timeout): \Generator {

lib/Controller/AdminController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public function exapp(): JSONResponse {
236236
$appId = $this->settingsService->getSetting('exapp.id');
237237
$exApp = $this->exAppService->getExApp($appId);
238238

239-
if ($exApp === null || !($exApp['enabled'] ?? false)) {
239+
if ($exApp === null || !(bool)($exApp['enabled'] ?? false)) {
240240
return new JSONResponse(['exapp' => false]);
241241
}
242242

lib/Service/ExAppService.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* the app_api app is not installed, so recognize keeps working with the local
2828
* node.js backend.
2929
*/
30-
class ExAppService {
30+
final class ExAppService {
3131
private const APP_API_APP_ID = 'app_api';
3232
private const APP_API_PUBLIC_FUNCTIONS = 'OCA\\AppAPI\\PublicFunctions';
3333

@@ -56,7 +56,10 @@ private function getPublicFunctions(): ?object {
5656
return null;
5757
}
5858
try {
59-
/** @psalm-suppress UndefinedClass */
59+
/**
60+
* @psalm-suppress UndefinedClass AppAPI is an optional dependency
61+
* @psalm-suppress MixedReturnStatement
62+
*/
6063
return \OCP\Server::get(self::APP_API_PUBLIC_FUNCTIONS);
6164
} catch (\Throwable $e) {
6265
$this->logger->warning('Could not load AppAPI PublicFunctions', ['exception' => $e]);
@@ -74,7 +77,11 @@ public function getExApp(string $appId): ?array {
7477
return null;
7578
}
7679
try {
77-
/** @psalm-suppress UndefinedClass */
80+
/**
81+
* @psalm-suppress UndefinedClass AppAPI is an optional dependency
82+
* @psalm-suppress MixedReturnStatement
83+
* @psalm-suppress MixedMethodCall
84+
*/
7885
return $publicFunctions->getExApp($appId);
7986
} catch (\Throwable $e) {
8087
$this->logger->warning('Could not query ExApp ' . $appId, ['exception' => $e]);
@@ -104,13 +111,18 @@ public function request(string $appId, string $route, string $method = 'POST', a
104111
throw new \RuntimeException('AppAPI is not available, cannot reach ExApp ' . $appId);
105112
}
106113

107-
/** @psalm-suppress UndefinedClass */
114+
/**
115+
* @psalm-suppress UndefinedClass AppAPI is an optional dependency
116+
* @psalm-suppress MixedAssignment
117+
* @psalm-suppress MixedMethodCall
118+
*/
108119
$response = $publicFunctions->exAppRequest($appId, $route, null, $method, $params, $options);
109120

110121
if (is_array($response) && isset($response['error'])) {
111-
throw new \RuntimeException('ExApp request to ' . $appId . $route . ' failed: ' . $response['error']);
122+
throw new \RuntimeException('ExApp request to ' . $appId . $route . ' failed: ' . (string)$response['error']);
112123
}
113124

125+
/** @psalm-suppress MixedReturnStatement */
114126
return $response;
115127
}
116128
}

0 commit comments

Comments
 (0)