fix: Fix psalm issues

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
This commit is contained in:
Marcel Klehr 2024-05-02 15:12:35 +02:00
parent 83ce5c75da
commit 30149ebe05
7 changed files with 30 additions and 29 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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));
}
/**

View File

@ -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) {

View File

@ -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;

View File

@ -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;

View File

@ -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 {