diff options
author | Marcel Klehr <mklehr@gmx.net> | 2024-05-02 15:12:35 +0200 |
---|---|---|
committer | Marcel Klehr <mklehr@gmx.net> | 2024-05-14 11:38:39 +0200 |
commit | 7a947980db9e8824a3c5c0f32a85af3f07a9ada9 (patch) | |
tree | 0b1b918de6ee96f65d44c8aaa7a83a5251ad5bc0 | |
parent | 1c033ae70a4a8a6d141e41a355cdcc38311eb966 (diff) | |
download | nextcloud-server-7a947980db9e8824a3c5c0f32a85af3f07a9ada9.tar.gz nextcloud-server-7a947980db9e8824a3c5c0f32a85af3f07a9ada9.zip |
fix: Fix psalm issues
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
-rw-r--r-- | core/Controller/TaskProcessingApiController.php | 31 | ||||
-rw-r--r-- | core/ResponseDefinitions.php | 6 | ||||
-rw-r--r-- | lib/private/TaskProcessing/Db/TaskMapper.php | 4 | ||||
-rw-r--r-- | lib/private/TaskProcessing/Manager.php | 6 | ||||
-rw-r--r-- | lib/public/TaskProcessing/IManager.php | 2 | ||||
-rw-r--r-- | lib/public/TaskProcessing/ISynchronousProvider.php | 4 | ||||
-rw-r--r-- | lib/public/TaskProcessing/Task.php | 6 |
7 files changed, 30 insertions, 29 deletions
diff --git a/core/Controller/TaskProcessingApiController.php b/core/Controller/TaskProcessingApiController.php index c3a2e9e0974..99d5755e10b 100644 --- a/core/Controller/TaskProcessingApiController.php +++ b/core/Controller/TaskProcessingApiController.php @@ -78,23 +78,27 @@ class TaskProcessingApiController extends \OCP\AppFramework\OCSController { public function taskTypes(): DataResponse { $taskTypes = $this->taskProcessingManager->getAvailableTaskTypes(); - /** @var string $typeClass */ - foreach ($taskTypes as $taskType) { - $taskType['inputShape'] = array_map(fn (ShapeDescriptor $descriptor) => $descriptor->jsonSerialize(), $taskType['inputShape']); - $taskType['optionalInputShape'] = array_map(fn (ShapeDescriptor $descriptor) => $descriptor->jsonSerialize(), $taskType['optionalInputShape']); - $taskType['outputShape'] = array_map(fn (ShapeDescriptor $descriptor) => $descriptor->jsonSerialize(), $taskType['outputShape']); - $taskType['optionalOutputShape'] = array_map(fn (ShapeDescriptor $descriptor) => $descriptor->jsonSerialize(), $taskType['optionalOutputShape']); + $serializedTaskTypes = []; + foreach ($taskTypes as $key => $taskType) { + $serializedTaskTypes[$key] = [ + 'name' => $taskType['name'], + 'description' => $taskType['description'], + 'inputShape' => array_map(fn (ShapeDescriptor $descriptor) => $descriptor->jsonSerialize(), $taskType['inputShape']), + 'optionalInputShape' => array_map(fn (ShapeDescriptor $descriptor) => $descriptor->jsonSerialize(), $taskType['optionalInputShape']), + 'outputShape' => array_map(fn (ShapeDescriptor $descriptor) => $descriptor->jsonSerialize(), $taskType['outputShape']), + 'optionalOutputShape' => array_map(fn (ShapeDescriptor $descriptor) => $descriptor->jsonSerialize(), $taskType['optionalOutputShape']), + ]; } return new DataResponse([ - 'types' => $taskTypes, + 'types' => $serializedTaskTypes, ]); } /** * This endpoint allows scheduling a task * - * @param string $input Input text + * @param array<array-key, mixed> $input Input text * @param string $type Type of the task * @param string $appId ID of the app that will execute the task * @param string $identifier An arbitrary identifier for the task @@ -162,10 +166,9 @@ class TaskProcessingApiController extends \OCP\AppFramework\OCSController { * * @param int $id The id of the task * - * @return DataResponse<Http::STATUS_OK, array{task: CoreTaskProcessingTask}, array{}>|DataResponse<Http::STATUS_NOT_FOUND|Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}> + * @return DataResponse<Http::STATUS_OK, array{}, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}> * * 200: Task returned - * 404: Task not found */ #[NoAdminRequired] #[ApiRoute(verb: 'DELETE', url: '/task/{id}', root: '/taskprocessing')] @@ -175,13 +178,9 @@ class TaskProcessingApiController extends \OCP\AppFramework\OCSController { $this->taskProcessingManager->deleteTask($task); - $json = $task->jsonSerialize(); - - return new DataResponse([ - 'task' => $json, - ]); + return new DataResponse([]); } catch (\OCP\TaskProcessing\Exception\NotFoundException $e) { - return new DataResponse(['message' => $this->l->t('Task not found')], Http::STATUS_NOT_FOUND); + return new DataResponse([]); } catch (\OCP\TaskProcessing\Exception\Exception $e) { return new DataResponse(['message' => $this->l->t('Internal error')], Http::STATUS_INTERNAL_SERVER_ERROR); } diff --git a/core/ResponseDefinitions.php b/core/ResponseDefinitions.php index 8025f7ef8a7..dd4196ec383 100644 --- a/core/ResponseDefinitions.php +++ b/core/ResponseDefinitions.php @@ -194,11 +194,11 @@ namespace OCA\Core; * * @psalm-type CoreTaskProcessingTask = array{ * id: ?int, - * status: int, + * status: 0|1|2|3|4|5, * userId: ?string, * appId: string, - * input: array<string, mixed>, - * output: ?array<string, mixed>, + * input: ?array<array-key, mixed>, + * output: ?array<array-key, mixed>, * identifier: ?string, * completionExpectedAt: ?int, * progress: ?float diff --git a/lib/private/TaskProcessing/Db/TaskMapper.php b/lib/private/TaskProcessing/Db/TaskMapper.php index f8a1adc695c..7ba16105f4c 100644 --- a/lib/private/TaskProcessing/Db/TaskMapper.php +++ b/lib/private/TaskProcessing/Db/TaskMapper.php @@ -104,7 +104,7 @@ class TaskMapper extends QBMapper { * @param string $userId * @param string $appId * @param string|null $identifier - * @return array + * @return list<Task> * @throws Exception */ public function findUserTasksByApp(string $userId, string $appId, ?string $identifier = null): array { @@ -116,7 +116,7 @@ class TaskMapper extends QBMapper { if ($identifier !== null) { $qb->andWhere($qb->expr()->eq('identifier', $qb->createPositionalParameter($identifier))); } - return $this->findEntities($qb); + return array_values($this->findEntities($qb)); } /** diff --git a/lib/private/TaskProcessing/Manager.php b/lib/private/TaskProcessing/Manager.php index 65307d4e435..8b145be8a65 100644 --- a/lib/private/TaskProcessing/Manager.php +++ b/lib/private/TaskProcessing/Manager.php @@ -162,7 +162,7 @@ class Manager implements IManager { } /** - * @return IProvider[] + * @return ITaskType[] */ private function _getTextProcessingTaskTypes(): array { $oldProviders = $this->textProcessingManager->getProviders(); @@ -304,6 +304,8 @@ class Manager implements IManager { private ISpeechToTextProvider $provider; private IAppData $appData; + private IRootFolder $rootFolder; + public function __construct(ISpeechToTextProvider $provider, IRootFolder $rootFolder, IAppData $appData) { $this->provider = $provider; $this->rootFolder = $rootFolder; @@ -711,7 +713,7 @@ class Manager implements IManager { public function getUserTasksByApp(?string $userId, string $appId, ?string $identifier = null): array { try { $taskEntities = $this->taskMapper->findUserTasksByApp($userId, $appId, $identifier); - return array_map(fn ($taskEntity) => $taskEntity->toPublicTask(), $taskEntities); + return array_map(fn ($taskEntity): Task => $taskEntity->toPublicTask(), $taskEntities); } catch (\OCP\DB\Exception $e) { throw new \OCP\TaskProcessing\Exception\Exception('There was a problem finding a task', 0, $e); } catch (\JsonException $e) { diff --git a/lib/public/TaskProcessing/IManager.php b/lib/public/TaskProcessing/IManager.php index 6c374d3fb35..ea85ce6c4fe 100644 --- a/lib/public/TaskProcessing/IManager.php +++ b/lib/public/TaskProcessing/IManager.php @@ -52,7 +52,7 @@ interface IManager { public function getProviders(): array; /** - * @return array<string,array{name: string, description: string, inputShape: ShapeDescriptor[], optionalInputShape: array<string, ShapeDescriptor>, outputShape: array<string, ShapeDescriptor>, optionalOutputShape: array<string, ShapeDescriptor>}> + * @return array<string,array{name: string, description: string, inputShape: ShapeDescriptor[], optionalInputShape: ShapeDescriptor[], outputShape: ShapeDescriptor[], optionalOutputShape: ShapeDescriptor[]}> * @since 30.0.0 */ public function getAvailableTaskTypes(): array; diff --git a/lib/public/TaskProcessing/ISynchronousProvider.php b/lib/public/TaskProcessing/ISynchronousProvider.php index e4fc0b1ea7f..0b17c6b6d86 100644 --- a/lib/public/TaskProcessing/ISynchronousProvider.php +++ b/lib/public/TaskProcessing/ISynchronousProvider.php @@ -40,8 +40,8 @@ interface ISynchronousProvider extends IProvider { * * @since 30.0.0 * @param null|string $userId The user that created the current task - * @param array<string, string> $input The task input - * @psalm-return array<string, string> + * @param array<string, mixed> $input The task input + * @psalm-return array<string, mixed> * @throws ProcessingException */ public function process(?string $userId, array $input): array; diff --git a/lib/public/TaskProcessing/Task.php b/lib/public/TaskProcessing/Task.php index 71b5dae84ca..58c420a9992 100644 --- a/lib/public/TaskProcessing/Task.php +++ b/lib/public/TaskProcessing/Task.php @@ -153,7 +153,7 @@ final class Task implements \JsonSerializable { } /** - * @return array<string, mixed>|null + * @return array<array-key, mixed>|null * @since 30.0.0 */ final public function getOutput(): ?array { @@ -161,7 +161,7 @@ final class Task implements \JsonSerializable { } /** - * @return array<string, mixed> + * @return array<array-key, mixed> * @since 30.0.0 */ final public function getInput(): array { @@ -193,7 +193,7 @@ final class Task implements \JsonSerializable { } /** - * @psalm-return array{id: ?int, status: self::STATUS_*, userId: ?string, appId: string, input: ?array, output: ?array, identifier: ?string, completionExpectedAt: ?int, progress: ?float} + * @psalm-return array{id: ?int, status: self::STATUS_*, userId: ?string, appId: string, input: ?array<array-key, mixed>, output: ?array<array-key, mixed>, identifier: ?string, completionExpectedAt: ?int, progress: ?float} * @since 30.0.0 */ public function jsonSerialize(): array { |