From fca8a17d4f70f93ac407aa91712860dce1ff26b1 Mon Sep 17 00:00:00 2001 From: Christian Hartmann Date: Wed, 12 Feb 2025 23:54:42 +0100 Subject: [PATCH 1/3] Fix(psalm): Update psalm baseline and fix undefined magic methods Signed-off-by: Christian Hartmann --- tests/psalm-baseline.xml | 227 +++------------------------------------ 1 file changed, 13 insertions(+), 214 deletions(-) diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index 334cc26bf..e001f1f88 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -1,247 +1,46 @@ - - - - formMapper->findbyHash($formHash)->getTitle(); - - // Append hash and route - $formLink .= $formHash; - if ($route !== '') { - $formLink .= '/' . $route; - } - } catch (IMapperException $e) { - // Ignore if not found, just use stored title - }]]> - - - - - UserDeletedListener::class - - + - - questionMapper->findById($questionId); - } catch (IMapperException $e) { - $this->logger->debug('Could not find question. Id:{id}', [ - 'id' => $questionId - ]); - throw new OCSBadRequestException(); - }]]> - formMapper->findByHash($hash); - } catch (IMapperException $e) { - $this->logger->debug('Could not find form'); - throw new OCSBadRequestException(); - }]]> - formMapper->findByHash($hash); - } catch (IMapperException $e) { - $this->logger->debug('Could not find form'); - throw new OCSBadRequestException(); - }]]> - formMapper->findByHash($hash); - } catch (IMapperException $e) { - $this->logger->debug('Could not find form'); - throw new OCSBadRequestException(); - }]]> - formMapper->findByHash($hash); - } catch (IMapperException $e) { - $this->logger->debug('Could not find form'); - throw new OCSBadRequestException(); - }]]> - formMapper->findById($formId); - $questions = $this->formsService->getQuestions($formId); - } catch (IMapperException $e) { - $this->logger->debug('Could not find form'); - throw new OCSBadRequestException(); - }]]> - formMapper->findById($formId); - } catch (IMapperException $e) { - $this->logger->debug('Could not find form'); - throw new OCSBadRequestException(); - }]]> - formMapper->findById($formId); - } catch (IMapperException $e) { - $this->logger->debug('Could not find form'); - throw new OCSBadRequestException(); - }]]> - formMapper->findById($formId); - } catch (IMapperException $e) { - $this->logger->debug('Could not find form'); - throw new OCSBadRequestException(); - }]]> - formMapper->findById($id); - } catch (IMapperException $e) { - $this->logger->debug('Could not find form'); - throw new OCSBadRequestException(); - }]]> - formMapper->findById($id); - } catch (IMapperException $e) { - $this->logger->debug('Could not find form'); - throw new OCSBadRequestException(); - }]]> - formsService->getForm($id); - } catch (IMapperException $e) { - $this->logger->debug('Could not find form'); - throw new OCSBadRequestException(); - }]]> - formMapper->findById($id); - } catch (IMapperException $e) { - $this->logger->debug('Could not find form'); - throw new OCSBadRequestException(); - }]]> - optionMapper->findById($id); - $question = $this->questionMapper->findById($option->getQuestionId()); - $form = $this->formMapper->findById($question->getFormId()); - } catch (IMapperException $e) { - $this->logger->debug('Could not find form or option'); - throw new OCSBadRequestException('Could not find form or option'); - }]]> - optionMapper->findById($id); - $question = $this->questionMapper->findById($option->getQuestionId()); - $form = $this->formMapper->findById($question->getFormId()); - } catch (IMapperException $e) { - $this->logger->debug('Could not find option, question or form'); - throw new OCSBadRequestException('Could not find option, question or form'); - }]]> - questionMapper->findById($id); - $form = $this->formMapper->findById($question->getFormId()); - } catch (IMapperException $e) { - $this->logger->debug('Could not find form or question'); - throw new OCSBadRequestException('Could not find form or question'); - }]]> - questionMapper->findById($id); - $form = $this->formMapper->findById($question->getFormId()); - } catch (IMapperException $e) { - $this->logger->debug('Could not find form or question'); - throw new OCSBadRequestException('Could not find form or question'); - }]]> - questionMapper->findById($questionId); - $form = $this->formMapper->findById($question->getFormId()); - } catch (IMapperException $e) { - $this->logger->debug('Could not find form or question'); - throw new OCSBadRequestException('Could not find form or question'); - }]]> - submissionMapper->findById($id); - $form = $this->formMapper->findById($submission->getFormId()); - } catch (IMapperException $e) { - $this->logger->debug('Could not find form or submission'); - throw new OCSBadRequestException(); - }]]> - - - - - formMapper->findById($formId); - } catch (IMapperException $e) { - $this->logger->debug('Could not find form', ['exception' => $e]); - throw new OCSBadRequestException('Could not find form'); - }]]> - shareMapper->findById($id); - $form = $this->formMapper->findById($share->getFormId()); - } catch (IMapperException $e) { - $this->logger->debug('Could not find share', ['exception' => $e]); - throw new OCSBadRequestException('Could not find share'); - }]]> - shareMapper->findById($id); - $form = $this->formMapper->findById($share->getFormId()); - } catch (IMapperException $e) { - $this->logger->debug('Could not find share', ['exception' => $e]); - throw new OCSBadRequestException('Could not find share'); - }]]> - + + mimeTypeDetector, 'getAllMappings')]]> + - getAccessEnum - setAccessEnum + + - getExtraSettingsJson - setExtraSettingsJson + + - getPermissionsJson - setPermissionsJson + + - - - OutputInterface - OutputInterface - - - - - request->server]]> - - - SecurityException - SecurityException - - - SecurityException - - - $result + ensureColumnIsNullable($schema, 'forms_v2_questions', 'mandatory')]]> - Type + - $result + ensureColumnIsNullable($schema, 'forms_v2_options', 'text')]]> ensureColumnIsNullable($schema, 'forms_v2_questions', 'order')]]> ensureColumnIsNullable($schema, 'forms_v2_questions', 'text')]]> ensureColumnIsNullable($schema, 'forms_v2_shares', 'share_type')]]> - - - IMapperException - IMapperException - IMapperException - - - - - storage]]> - IRootFolder - IRootFolder - - From 2bab0bf917622e743c32a24090dc364fe09e94ca Mon Sep 17 00:00:00 2001 From: Christian Hartmann Date: Thu, 13 Feb 2025 00:03:17 +0100 Subject: [PATCH 2/3] Refactor: Add return types to multiple methods for improved type safety Signed-off-by: Christian Hartmann --- lib/Activity/ActivityManager.php | 13 ++++++++----- lib/Controller/ApiController.php | 4 +++- lib/Controller/PageController.php | 4 +++- lib/Db/Form.php | 2 +- lib/Db/Question.php | 2 +- lib/Db/Share.php | 2 +- lib/Migration/Version010200Date20200323141300.php | 3 +++ lib/Migration/Version020202Date20210311150843.php | 3 +++ lib/Migration/Version020300Date20210406114130.php | 5 ++++- lib/Migration/Version040200Date20240219201500.php | 2 ++ lib/Service/FormsService.php | 2 +- 11 files changed, 30 insertions(+), 12 deletions(-) diff --git a/lib/Activity/ActivityManager.php b/lib/Activity/ActivityManager.php index c8a16a31d..5d88237ac 100644 --- a/lib/Activity/ActivityManager.php +++ b/lib/Activity/ActivityManager.php @@ -28,10 +28,11 @@ public function __construct( /** * Publish a new-Share Activity + * * @param Form $form The shared form * @param string $shareeId UserId, the form has been shared to */ - public function publishNewShare(Form $form, string $shareeId) { + public function publishNewShare(Form $form, string $shareeId): void { $event = $this->manager->generateEvent(); $event->setApp($this->appName) ->setType(ActivityConstants::TYPE_NEWSHARE) @@ -49,10 +50,11 @@ public function publishNewShare(Form $form, string $shareeId) { /** * Publish a new-GroupShare Activity to each affected user + * * @param Form $form The shared form * @param string $groupId Group the form has been shared to */ - public function publishNewGroupShare(Form $form, string $groupId) { + public function publishNewGroupShare(Form $form, string $groupId): void { $affectedUsers = $this->groupManager->get($groupId)->getUsers(); foreach ($affectedUsers as $user) { @@ -79,7 +81,7 @@ public function publishNewGroupShare(Form $form, string $groupId) { * @param Form $form The shared form * @param string $circleId Circle the form has been shared to */ - public function publishNewCircleShare(Form $form, string $circleId) { + public function publishNewCircleShare(Form $form, string $circleId): void { $users = $this->circlesService->getCircleUsers($circleId); foreach ($users as $user) { @@ -102,10 +104,11 @@ public function publishNewCircleShare(Form $form, string $circleId) { /** * Publish a new-Submission Activity + * * @param Form $form The affected Form * @param string $submitterID ID of the User who submitted the form. Can also be our 'anon-user-'-ID */ - public function publishNewSubmission(Form $form, string $submitterID) { + public function publishNewSubmission(Form $form, string $submitterID): void { $event = $this->manager->generateEvent(); $event->setApp($this->appName) ->setType(ActivityConstants::TYPE_NEWSUBMISSION) @@ -127,7 +130,7 @@ public function publishNewSubmission(Form $form, string $submitterID) { * @param Form $form The affected Form * @param string $submitterID ID of the User who submitted the form. Can also be our 'anon-user-'-ID */ - public function publishNewSharedSubmission(Form $form, int $shareType, string $shareWith, string $submitterID) { + public function publishNewSharedSubmission(Form $form, int $shareType, string $shareWith, string $submitterID): void { $users = []; switch ($shareType) { case IShare::TYPE_USER: diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 4072dedc1..d9a827f13 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -96,6 +96,8 @@ public function __construct( // CORS preflight /** * Handle CORS options request by calling parent function + * + * @return void */ #[ApiRoute(verb: 'OPTIONS', url: '/api/v3/{path}', requirements: ['path' => '.+'])] public function preflightedCors() { @@ -1527,7 +1529,7 @@ public function uploadFiles(int $formId, int $questionId, string $shareHash = '' * @param array $question * @param string[]|array $answerArray */ - private function storeAnswersForQuestion(Form $form, $submissionId, array $question, array $answerArray) { + private function storeAnswersForQuestion(Form $form, $submissionId, array $question, array $answerArray): void { foreach ($answerArray as $answer) { $answerEntity = new Answer(); $answerEntity->setSubmissionId($submissionId); diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 71b5ebe47..8dc1ae1dc 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -248,8 +248,10 @@ protected function insertHeaderOnIos(): void { /** * Set CSP options to allow the page be embedded using