Skip to content

Commit

Permalink
fix(psalm): Fix syntax problems
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Oct 28, 2024
1 parent 8de8000 commit c0299b4
Show file tree
Hide file tree
Showing 6 changed files with 1,206 additions and 82 deletions.
58 changes: 29 additions & 29 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function preflightedCors() {
* Possible values:
* - `owned`: Forms owned by the user.
* - `shared`: Forms shared with the user.
* @return DataResponse<array<FormsPartialForm>, Http::STATUS_OK, array<>>
* @return DataResponse<Http::STATUS_OK, array<FormsPartialForm>, array{}>
* @throws OCSBadRequestException wrong form type supplied
*/
#[CORS()]
Expand Down Expand Up @@ -156,7 +156,7 @@ public function getForms(string $type = 'owned'): DataResponse {
* Return a copy of the form if the parameter $fromId is set
*
* @param ?int $fromId (optional) Id of the form that should be cloned
* @return DataResponse<FormsForm, Http::STATUS_CREATED, array<>>
* @return DataResponse<Http::STATUS_CREATED, FormsForm, array{}>
* @throws OCSForbiddenException The user is not allowed to create forms
*/
#[CORS()]
Expand Down Expand Up @@ -231,7 +231,7 @@ public function newForm(?int $fromId = null): DataResponse {
* Read all information to edit a Form (form, questions, options, except submissions/answers)
*
* @param int $formId Id of the form
* @return DataResponse<array<FormsForm>, Http::STATUS_OK, array<>>
* @return DataResponse<Http::STATUS_OK, array<FormsForm>, array{}>
* @throws OCSBadRequestException Could not find form
* @throws OCSForbiddenException User has no permissions to get this form
*/
Expand Down Expand Up @@ -259,7 +259,7 @@ public function getForm(int $formId): DataResponse {
*
* @param int $formId FormId of form to update
* @param array<string, mixed> $keyValuePairs Array of key=>value pairs to update.
* @return DataResponse<int formId, Http::STATUS_OK, array<>>
* @return DataResponse<Http::STATUS_OK, int, array{}>

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

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable30

InvalidReturnType

lib/Controller/ApiController.php:262:13: InvalidReturnType: The declared return type 'OCP\AppFramework\Http\DataResponse<200, int, array<never, never>>' for OCA\Forms\Controller\ApiController::updateForm is incorrect, got 'OCP\AppFramework\Http\DataResponse<200, int, array<never, never>>|OCP\AppFramework\Http\DataResponse<200, string, array<never, never>>' (see https://psalm.dev/011)
* @throws OCSBadRequestException Could not find new form owner
* @throws OCSForbiddenException Empty keyValuePairs provided
* @throws OCSForbiddenException Not allowed to update id, hash, created, fileId or lastUpdated. OwnerId only allowed if no other key provided.
Expand Down Expand Up @@ -349,7 +349,7 @@ public function updateForm(int $formId, array $keyValuePairs): DataResponse {
* Delete a form
*
* @param int $formId the form id
* @return DataResponse<int formId, Http::STATUS_OK, array<>>
* @return DataResponse<Http::STATUS_OK, int, array{}>
* @throws OCSForbiddenException User is not allowed to delete the form
* @throws OCSNotFoundException Form not found
*/
Expand All @@ -372,7 +372,7 @@ public function deleteForm(int $formId): DataResponse {
* Read all questions (including options)
*
* @param int $formId the form id
* @return DataResponse<array<FormQuestion>, Http::STATUS_OK, array<>>
* @return DataResponse<Http::STATUS_OK, array<FormsQuestion>, array{}>
* @throws OCSForbiddenException User has no permissions to get this form
* @throws OCSNotFoundException Could not find form
*/
Expand Down Expand Up @@ -402,7 +402,7 @@ public function getQuestions(int $formId): DataResponse {
*
* @param int $formId FormId
* @param int $questionId QuestionId
* @return DataResponse<FormQuestion, Http::STATUS_OK, array<>>
* @return DataResponse<Http::STATUS_OK, FormsQuestion, array{}>
* @throws OCSBadRequestException Question doesn\'t belong to given Form
* @throws OCSForbiddenException User has no permissions to get this form
* @throws OCSNotFoundException Could not find form
Expand Down Expand Up @@ -439,7 +439,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<FormQuestion, Http::STATUS_CREATED, array<>>
* @return DataResponse<Http::STATUS_CREATED, FormsQuestion, array{}>

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

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable30

InvalidReturnType

lib/Controller/ApiController.php:442:13: InvalidReturnType: The declared return type 'OCP\AppFramework\Http\DataResponse<201, array{accept: array<array-key, string>, extraSettings: stdClass, formId: int, id: int, isRequired: bool, name: string, options: array<array-key, array{id: int, order: int|null, questionId: int, text: string}>, order: int, text: string, type: string}, array<never, never>>' for OCA\Forms\Controller\ApiController::newQuestion is incorrect, got '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/011)
* @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 @@ -549,7 +549,7 @@ public function newQuestion(int $formId, ?string $type = null, string $text = ''
* @param int $formId the form id
* @param int $questionId id of question to update
* @param array<string, mixed> $keyValuePairs Array of key=>value pairs to update.
* @return DataResponse<int id, Http::STATUS_OK, array<>>
* @return DataResponse<Http::STATUS_OK, int, array{}>
* @throws OCSBadRequestException Question doesn\'t belong to given Form
* @throws OCSBadRequestException Invalid extraSettings, will not update.
* @throws OCSForbiddenException Empty keyValuePairs, will not update
Expand Down Expand Up @@ -590,7 +590,7 @@ public function updateQuestion(int $formId, int $questionId, array $keyValuePair
// Don't allow empty array
if (sizeof($keyValuePairs) === 0) {
$this->logger->info('Empty keyValuePairs, will not update.');
throw new OCSBacRequestException('This form is archived and can not be modified');
throw new OCSBadRequestException('This form is archived and can not be modified');

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

View check run for this annotation

Codecov / codecov/patch

lib/Controller/ApiController.php#L593

Added line #L593 was not covered by tests
}

//Don't allow to change id or formId
Expand Down Expand Up @@ -625,7 +625,7 @@ public function updateQuestion(int $formId, int $questionId, array $keyValuePair
*
* @param int $formId the form id
* @param int $questionId the question id
* @return DataResponse<int id, Http::STATUS_OK, array<>>
* @return DataResponse<Http::STATUS_OK, int, array{}>
* @throws OCSBadRequestException Question doesn\'t belong to given Form
* @throws OCSForbiddenException This form is archived and can not be modified
* @throws OCSForbiddenException User has no permissions to get this form
Expand Down Expand Up @@ -684,7 +684,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<array<int, int>, Http::STATUS_OK, array<>>
* @return DataResponse<Http::STATUS_OK, array<string, int>, array{}>

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

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable30

InvalidReturnType

lib/Controller/ApiController.php:687:13: InvalidReturnType: The declared return type 'OCP\AppFramework\Http\DataResponse<200, array<string, int>, array<never, never>>' for OCA\Forms\Controller\ApiController::reorderQuestions is incorrect, got 'OCP\AppFramework\Http\DataResponse<200, array<int, array{order: int}>, array<never, never>>' (see https://psalm.dev/011)
* @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 @@ -782,7 +782,7 @@ public function reorderQuestions(int $formId, array $newOrder): DataResponse {
* @param int $formId id of the form
* @param int $questionId id of the question
* @param array<string> $optionTexts the new option text
* @return DataResponse<array<FormsOption>, Http::STATUS_CREATED, array<>> Returns a DataResponse containing the added options
* @return DataResponse<Http::STATUS_CREATED, array<FormsOption>, array{}> Returns a DataResponse containing the added options
* @throws OCSBadRequestException This question is not part ot the given form
* @throws OCSForbiddenException This form is archived and can not be modified
* @throws OCSForbiddenException Current user has no permission to edit
Expand All @@ -804,7 +804,7 @@ public function newOption(int $formId, int $questionId, array $optionTexts): Dat
$this->logger->debug('This form is archived and can not be modified');
throw new OCSForbiddenException('This form is archived and can not be modified');

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

View check run for this annotation

Codecov / codecov/patch

lib/Controller/ApiController.php#L805

Added line #L805 was not covered by tests
}

try {
$question = $this->questionMapper->findById($questionId);
} catch (IMapperException $e) {
Expand Down Expand Up @@ -858,7 +858,7 @@ public function newOption(int $formId, int $questionId, array $optionTexts): Dat
* @param int $questionId id of question
* @param int $optionId id of option to update
* @param array{key: string, value: mixed} $keyValuePairs Array of key=>value pairs to update.
* @return DataResponse<id: int, Http::STATUS_OK, array<>> Returns the id of the updated option
* @return DataResponse<Http::STATUS_OK, int, array{}> Returns the id of the updated option
* @throws OCSBadRequestException The given option id doesn't match the question or form
* @throws OCSForbiddenException This form is archived and can not be modified
* @throws OCSForbiddenException Current user has no permission to edit
Expand Down Expand Up @@ -927,7 +927,7 @@ public function updateOption(int $formId, int $questionId, int $optionId, array
* @param int $formId id of form
* @param int $questionId id of question
* @param int $optionId id of option to update
* @return DataResponse<id: int, Http::STATUS_OK, array<>> Returns the id of the deleted option
* @return DataResponse<Http::STATUS_OK, int, array{}> Returns the id of the deleted option
* @throws OCSBadRequestException The given option id doesn't match the question or form
* @throws OCSForbiddenException This form is archived and can not be modified
* @throws OCSForbiddenException Current user has no permission to edit
Expand All @@ -947,7 +947,7 @@ public function deleteOption(int $formId, int $questionId, int $optionId): DataR
$this->logger->debug('This form is archived and can not be modified');
throw new OCSForbiddenException('This form is archived and can not be modified');

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

View check run for this annotation

Codecov / codecov/patch

lib/Controller/ApiController.php#L948

Added line #L948 was not covered by tests
}

try {
$option = $this->optionMapper->findById($optionId);
$question = $this->questionMapper->findById($questionId);
Expand Down Expand Up @@ -981,7 +981,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<array<int, int>, Http::STATUS_OK, array<>>
* @return DataResponse<Http::STATUS_OK, array<string, 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 @@ -1018,14 +1018,14 @@ public function reorderOptions(int $formId, int $questionId, array $newOrder) {
$this->logger->debug('The given array contains duplicates');
throw new OCSBadRequestException('The given array contains duplicates');
}

$options = $this->optionMapper->findByQuestion($questionId);

if (sizeof($options) !== sizeof($newOrder)) {
$this->logger->debug('The length of the given array does not match the number of stored options');
throw new OCSBadRequestException('The length of the given array does not match the number of stored options');
}

$options = []; // Clear Array of Entities
$response = []; // Array of ['optionId' => ['order' => newOrder]]

Expand Down Expand Up @@ -1061,13 +1061,13 @@ public function reorderOptions(int $formId, int $questionId, array $newOrder) {
foreach ($options as $option) {
$this->optionMapper->update($option);

$response[$option->getId()] = [
$response[(string)$option->getId()] = [

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

View check run for this annotation

Codecov / codecov/patch

lib/Controller/ApiController.php#L1064

Added line #L1064 was not covered by tests
'order' => $option->getOrder()
];
}

$this->formMapper->update($form);

return new DataResponse($response);
}

Expand All @@ -1082,7 +1082,7 @@ public function reorderOptions(int $formId, int $questionId, array $newOrder) {
* - `csv`: Comma-separated value
* - `ods`: OpenDocument Spreadsheet
* - `xlsx`: Excel Open XML Spreadsheet
* @return DataResponse|DataDownloadResponse<FormsSubmissions, Http::STATUS_OK, array<>>
* @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{}>
* @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 @@ -1143,7 +1143,7 @@ public function getSubmissions(int $formId, ?string $fileFormat = null): DataRes
* Delete all submissions of a specified form
*
* @param int $formId the form id
* @return DataResponse<int: formId, Http::STATUS_OK, array<>>
* @return DataResponse<Http::STATUS_OK, int, array{}>
* @throws OCSNotFoundException Could not find form
* @throws OCSForbiddenException This form is not owned by the current user and user has no `results_delete` permission
*/
Expand Down Expand Up @@ -1181,7 +1181,7 @@ public function deleteAllSubmissions(int $formId): DataResponse {
* @param int $formId the form id
* @param array<string, array<string>> $answers [question_id => arrayOfString]
* @param string $shareHash public share-hash -> Necessary to submit on public link-shares.
* @return DataResponse<array<>, Http::STATUS_CREATED, array<>>
* @return DataResponse<Http::STATUS_CREATED, null, array{}>
* @throws OCSBadRequestException At least one submitted answer is not valid
* @throws OCSForbiddenException Already submitted
* @throws OCSForbiddenException Not allowed to access this form
Expand Down Expand Up @@ -1280,7 +1280,7 @@ public function newSubmission(int $formId, array $answers, string $shareHash = '
*
* @param int $formId the form id
* @param int $submissionId the submission id
* @return DataResponse<int: submissionId, Http::STATUS_OK, array<>>
* @return DataResponse<Http::STATUS_OK, int, array{}>
* @throws OCSBadRequestException Submission doesn't belong to given form
* @throws OCSNotFoundException Could not find form or submission
* @throws OCSForbiddenException This form is not owned by the current user and user has no `results_delete` permission
Expand Down Expand Up @@ -1325,7 +1325,7 @@ public function deleteSubmission(int $formId, int $submissionId): DataResponse {
* @param int $formId of the form
* @param string $path The Cloud-Path to export to
* @param string $fileFormat File format used for export
* @return DataResponse<string: fileName, Http::STATUS_OK, array<>>
* @return DataResponse<Http::STATUS_OK, string, array{}>
* @throws OCSForbiddenException The current user has no permission to get the results for this form
* @throws OCSNotFoundException Could not find form
*/
Expand Down Expand Up @@ -1356,7 +1356,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<FormsUploadedFile, Http::STATUS_OK, array<>>
* @return DataResponse<Http::STATUS_OK, FormsUploadedFile, array{}>
* @throws OCSBadRequestException No files provided
* @throws OCSBadRequestException Question doesn't belong to the given form
* @throws OCSBadRequestException Invalid file provided
Expand Down
1 change: 1 addition & 0 deletions lib/Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\DataResponse;
use OCP\IConfig;
use OCP\IRequest;
Expand Down
5 changes: 3 additions & 2 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\Attribute\PublicPage;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\RedirectResponse;
Expand Down Expand Up @@ -171,9 +172,9 @@ public function embeddedFormView(string $hash): Response {
Util::addStyle($this->appName, 'embedded');
$response = $this->createPublicSubmitView($form, $hash)
->renderAs(TemplateResponse::RENDER_AS_BASE);

$this->initialState->provideInitialState('isEmbedded', true);

return $this->setEmbeddedCSP($response);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Controller/ShareApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function __construct(
* - `submit` user can submit
* - `results` user can see the results
* - `results_delete` user can see and delete results
* @return DataResponse<array<FormsShare>, Http::STATUS_CREATED, array<>>
* @return DataResponse<Http::STATUS_CREATED, FormsShare, array{}>
* @throws OCSBadRequestException Invalid shareType
* @throws OCSBadRequestException Invalid permission given
* @throws OCSBadRequestException Invalid user to share with
Expand Down Expand Up @@ -230,7 +230,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.
* @return DataResponse<array<int>, Http::STATUS_OK, array<>>
* @return DataResponse<Http::STATUS_OK, int, array{}>
* @throws OCSBadRequestException Share doesn't belong to given Form
* @throws OCSBadRequestException Invalid permission given
* @throws OCSForbiddenException This form is not owned by the current user
Expand Down Expand Up @@ -325,7 +325,7 @@ public function updateShare(int $formId, int $shareId, array $keyValuePairs): Da
*
* @param int $formId of the form
* @param int $shareId of the share to delete
* @return DataResponse<array<int>, Http::STATUS_OK, array<>>
* @return DataResponse<Http::STATUS_OK, int, array{}>
* @throws OCSBadRequestException Share doesn't belong to given Form
* @throws OCSForbiddenException This form is not owned by the current user
* @throws OCSNotFoundException Could not find share
Expand Down
Loading

0 comments on commit c0299b4

Please sign in to comment.