Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Hartmann <[email protected]>
  • Loading branch information
Chartman123 committed Oct 29, 2024
1 parent cfcde6b commit 90c3a94
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 141 deletions.
14 changes: 7 additions & 7 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public function getQuestion(int $formId, int $questionId): DataResponse {
* @param string $type the new question type
* @param string $text the new question title
* @param ?int $fromId (optional) id of the question that should be cloned
* @return DataResponse<Http::STATUS_CREATED, FormsQuestion, array{}>
* @return DataResponse<Http::STATUS_CREATED, list<FormsQuestion>, array{}>

Check failure on line 456 in lib/Controller/ApiController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable30

MoreSpecificReturnType

lib/Controller/ApiController.php:456:13: MoreSpecificReturnType: The declared return type 'OCP\AppFramework\Http\DataResponse<201, list<array{accept?: list<string>|null, description: string, extraSettings: array{0?: never, allowOtherAnswer?: bool|null, allowedFileExtensions?: list<string>|null, allowedFileTypes?: list<string>|null, maxAllowedFilesCount?: int|null, maxFileSize?: int|null, optionsLimitMax?: int|null, optionsLimitMin?: int|null, shuffleOptions?: bool|null, validationRegex?: null|string, validationType?: null|string, ...<int<0, max>, never>}, formId: int, id: int, isRequired: bool, name: string, options: list<array{id: int, order: int|null, questionId: int, text: string}>|null, order: int, text: string, type: string}>, array<never, never>>' for OCA\Forms\Controller\ApiController::newQuestion is more specific than the inferred return type 'OCP\AppFramework\Http\DataResponse<201, array{accept: array<never, never>, options: list<array<array-key, mixed>>, ...<array-key, mixed>}, array<never, never>>' (see https://psalm.dev/070)
* @throws OCSBadRequestException Invalid type
* @throws OCSBadRequestException Datetime question type no longer supported
* @throws OCSForbiddenException User has no permissions to get this form
Expand Down Expand Up @@ -704,7 +704,7 @@ public function deleteQuestion(int $formId, int $questionId): DataResponse {
*
* @param int $formId Id of the form to reorder
* @param array<string, int> $newOrder Array of Question-Ids in new order.
* @return DataResponse<Http::STATUS_OK, array<string, int>, array{}>
* @return DataResponse<Http::STATUS_OK, list<string, list<order: int>>, array{}>
* @throws OCSBadRequestException The given array contains duplicates
* @throws OCSBadRequestException The length of the given array does not match the number of stored questions
* @throws OCSBadRequestException Question doesn\'t belong to given Form
Expand Down Expand Up @@ -1009,7 +1009,7 @@ public function deleteOption(int $formId, int $questionId, int $optionId): DataR
* @param int $formId id of form
* @param int $questionId id of question
* @param array<string, int> $newOrder Array of option ids in new order.
* @return DataResponse<Http::STATUS_OK, array<string, int>, array{}>
* @return DataResponse<Http::STATUS_OK, array<string, array<order: int>>, array{}>
* @throws OCSBadRequestException The given question id doesn't match the form
* @throws OCSBadRequestException The given array contains duplicates
* @throws OCSBadRequestException The length of the given array does not match the number of stored options
Expand Down Expand Up @@ -1081,9 +1081,9 @@ public function reorderOptions(int $formId, int $questionId, array $newOrder) {
$oldOrder = $options[$arrayKey]->getOrder();

// Only set order, if it changed.
if ($oldOrder !== $arrayKey + 1) {
if ($oldOrder !== (int)$arrayKey + 1) {

Check warning on line 1084 in lib/Controller/ApiController.php

View check run for this annotation

Codecov / codecov/patch

lib/Controller/ApiController.php#L1084

Added line #L1084 was not covered by tests
// Set Order. ArrayKey counts from zero, order counts from 1.
$options[$arrayKey]->setOrder($arrayKey + 1);
$options[$arrayKey]->setOrder((int)$arrayKey + 1);

Check warning on line 1086 in lib/Controller/ApiController.php

View check run for this annotation

Codecov / codecov/patch

lib/Controller/ApiController.php#L1086

Added line #L1086 was not covered by tests
}
}

Expand Down Expand Up @@ -1112,7 +1112,7 @@ public function reorderOptions(int $formId, int $questionId, array $newOrder) {
* - `csv`: Comma-separated value
* - `ods`: OpenDocument Spreadsheet
* - `xlsx`: Excel Open XML Spreadsheet
* @return DataResponse<Http::STATUS_OK, FormsSubmissions, array{}>|DataDownloadResponse<Http::STATUS_OK, 'text/csv'|'application/vnd.oasis.opendocument.spreadsheet'|'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', array{}>
* @return DataResponse<Http::STATUS_OK, list<FormsSubmissions>, array{}>|DataDownloadResponse<Http::STATUS_OK, 'text/csv'|'application/vnd.oasis.opendocument.spreadsheet'|'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', array{}>

Check failure on line 1115 in lib/Controller/ApiController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable30

MoreSpecificReturnType

lib/Controller/ApiController.php:1115:13: MoreSpecificReturnType: The declared return type 'OCP\AppFramework\Http\DataDownloadResponse<200, 'application/vnd.oasis.opendocument.spreadsheet'|'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'|'text/csv', array<never, never>>|OCP\AppFramework\Http\DataResponse<200, list<array{questions: list<array{accept?: list<string>|null, description: string, extraSettings: array{0?: never, allowOtherAnswer?: bool|null, allowedFileExtensions?: list<string>|null, allowedFileTypes?: list<string>|null, maxAllowedFilesCount?: int|null, maxFileSize?: int|null, optionsLimitMax?: int|null, optionsLimitMin?: int|null, shuffleOptions?: bool|null, validationRegex?: null|string, validationType?: null|string, ...<int<0, max>, never>}, formId: int, id: int, isRequired: bool, name: string, options: list<array{id: int, order: int|null, questionId: int, text: string}>|null, order: int, text: string, type: string}>, submissions: list<array{answers: list<array{id: int, questionId: int, submissionId: int, text: string}>, formId: int, id: int, timestamp: int, userDisplayName: string, userId: string}>}>, array<never, never>>' for OCA\Forms\Controller\ApiController::getSubmissions is more specific than the inferred return type 'OCP\AppFramework\Http\DataDownloadResponse<200, 'application/vnd.oasis.opendocument.spreadsheet'|'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'|'text/csv', array<never, never>>|OCP\AppFramework\Http\DataResponse<200, array{questions: array<array-key, mixed>, submissions: array<array-key, mixed>}, array<never, never>>' (see https://psalm.dev/070)
* @throws OCSNotFoundException Could not find form
* @throws OCSForbiddenException The current user has no permission to get the results for this form
*
Expand Down Expand Up @@ -1396,7 +1396,7 @@ public function exportSubmissionsToCloud(int $formId, string $path, string $file
* @param int $formId id of the form
* @param int $questionId id of the question
* @param string $shareHash hash of the form share
* @return DataResponse<Http::STATUS_OK, FormsUploadedFile, array{}>
* @return DataResponse<Http::STATUS_OK, list<FormsUploadedFile>, array{}>
* @throws OCSBadRequestException No files provided
* @throws OCSBadRequestException Question doesn't belong to the given form
* @throws OCSBadRequestException Invalid file provided
Expand Down
16 changes: 8 additions & 8 deletions lib/Controller/ShareApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ public function __construct(
* @param int $formId The form to share
* @param int $shareType Nextcloud-ShareType
* @param string $shareWith ID of user/group/... to share with. For Empty shareWith and shareType Link, this will be set as RandomID.
* @param array<string> $permissions the permissions granted on the share, defaults to `submit`
* Possible values:
* - `submit` user can submit
* - `results` user can see the results
* - `results_delete` user can see and delete results
* @return DataResponse<Http::STATUS_CREATED, FormsShare, array{}>
* @param list<string> $permissions the permissions granted on the share, defaults to `submit`
* Possible values:
* - `submit` user can submit
* - `results` user can see the results
* - `results_delete` user can see and delete results
* @return DataResponse<Http::STATUS_CREATED, array<FormsShare>, array{}>
* @throws OCSBadRequestException Invalid shareType
* @throws OCSBadRequestException Invalid permission given
* @throws OCSBadRequestException Invalid user to share with
Expand Down Expand Up @@ -231,7 +231,7 @@ public function newShare(int $formId, int $shareType, string $shareWith = '', ar
*
* @param int $formId of the form
* @param int $shareId of the share to update
* @param array{key: string, values: mixed} $keyValuePairs Array of key=>value pairs to update.
* @param array<string, mixed> $keyValuePairs Array of key=>value pairs to update.
* @return DataResponse<Http::STATUS_OK, int, array{}>
* @throws OCSBadRequestException Share doesn't belong to given Form
* @throws OCSBadRequestException Invalid permission given
Expand Down Expand Up @@ -277,7 +277,7 @@ public function updateShare(int $formId, int $shareId, array $keyValuePairs): Da
}

//Don't allow to change other properties than permissions
if (count($keyValuePairs) > 1 || !key_exists('permissions', $keyValuePairs)) {
if (count($keyValuePairs) > 1 || !array_key_exists('permissions', $keyValuePairs)) {
$this->logger->debug('Not allowed to update other properties than permissions');
throw new OCSForbiddenException('Not allowed to update other properties than permissions');

Check warning on line 282 in lib/Controller/ShareApiController.php

View check run for this annotation

Codecov / codecov/patch

lib/Controller/ShareApiController.php#L282

Added line #L282 was not covered by tests
}
Expand Down
81 changes: 51 additions & 30 deletions lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,26 @@
namespace OCA\Forms;

/**
* @psalm-type FormsPartialForm = array{
* id: int,
* hash: string,
* title: string,
* expires: int,
* permissions: string[],
* partial: bool,
* state: int
* }
*
* @psalm-type FormsOption = array{
* id: int,
* questionId: int,
* text: string,
* order: ?int
* }
*
* @psalm-type FormsQuestionExtraSettings = array{
* allowOtherAnswer?: ?bool,
* allowedFileExtensions?: ?list<string>,
* allowedFileTypes?: ?list<string>,
* maxAllowedFilesCount?: ?int,
* maxFileSize?: ?int,
* optionsLimitMax?: ?int,
* optionsLimitMin?: ?int,
* shuffleOptions?: ?bool,
* validationRegex?: ?string,
* validationType?: ?string
* }
*
* @psalm-type FormsQuestion = array{
* id: int,
* formId: int,
Expand All @@ -49,9 +52,10 @@
* isRequired: bool,
* text: string,
* name: string,
* options: array<FormsOption>,
* accept: string[],
* extraSettings: \stdClass
* description: string,
* extraSettings: list<empty>|FormsQuestionExtraSettings,
* options: ?list<FormsOption>,
* accept?: ?list<string>
* }
*
* @psalm-type FormsAnswer = array{
Expand All @@ -66,13 +70,39 @@
* formId: int,
* userId: string,
* timestamp: int,
* answers: array<FormsAnswer>,
* answers: list<FormsAnswer>,
* userDisplayName: string
* }
*
* @psalm-type FormsSubmissions = array{
* submissions: array<FormsSubmission>,
* questions: array<FormsQuestion>
* submissions: list<FormsSubmission>,
* questions: list<FormsQuestion>
* }
*
* @psalm-type FormsAccess = array{
* permitAllUsers: bool,
* showToAllUsers: bool
* }
*
* @psalm-type FormsPermission = "edit"|"results"|"results_delete"|"submit"|"embed"
*
* @psalm-type FormsShare = array{
* id: int,
* formId: int,
* shareType: int,
* shareWith: string,
* permissions: list<FormsPermission>,
* displayName: string
* }
*
* @psalm-type FormsPartialForm = array{
* id: int,
* hash: string,
* title: string,
* expires: int,
* permissions: list<FormsPermission>,
* partial: true,
* state: int
* }
*
* @psalm-type FormsForm = array{
Expand All @@ -82,32 +112,23 @@
* description: string,
* ownerId: string,
* created: int,
* access: \stdClass,
* access: FormsAccess,
* expires: int,
* isAnonymous: bool,
* submitMultiple: bool,
* showExpiration: bool,
* canSubmit: bool,
* permissions: string[],
* questions: array<FormsQuestion>,
* permissions: list<FormsPermission>,
* questions: list<FormsQuestion>,
* state: int,
* shares: string[],
* submissions: array<FormsSubmission>,
* shares: list<string>,
* submissions: list<FormsSubmission>,
* }
*
* @psalm-type FormsUploadedFile = array{
* uploadedFileId: int,
* fileName: string
* }
*
* @psalm-type FormsShare = array{
* id: int,
* formId: int,
* shareType: int,
* shareWith: string,
* permissions: string[],
* displayName: string
* }
*/
class ResponseDefinitions {
}
Loading

0 comments on commit 90c3a94

Please sign in to comment.