diff --git a/lib/Command/Configure/Cfssl.php b/lib/Command/Configure/Cfssl.php index 82ed9e57ed..a577cd433a 100644 --- a/lib/Command/Configure/Cfssl.php +++ b/lib/Command/Configure/Cfssl.php @@ -28,7 +28,6 @@ use OCA\Libresign\Command\Base; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Output\OutputInterface; class Cfssl extends Base { protected function configure(): void { @@ -85,7 +84,7 @@ protected function configure(): void { ); } - protected function execute(InputInterface $input, OutputInterface $output): int { + protected function execute(InputInterface $input): int { if (!$this->installService->isCfsslBinInstalled()) { throw new InvalidArgumentException('CFSSL binary not found! run libresign:istall --cfssl first.'); } diff --git a/lib/Command/Configure/OpenSsl.php b/lib/Command/Configure/OpenSsl.php index f0844be7be..f8386ff094 100644 --- a/lib/Command/Configure/OpenSsl.php +++ b/lib/Command/Configure/OpenSsl.php @@ -28,7 +28,6 @@ use OCA\Libresign\Command\Base; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Output\OutputInterface; class OpenSsl extends Base { protected function configure(): void { @@ -79,7 +78,7 @@ protected function configure(): void { ); } - protected function execute(InputInterface $input, OutputInterface $output): int { + protected function execute(InputInterface $input): int { $names = []; if (!$commonName = $input->getOption('cn')) { throw new InvalidArgumentException('Invalid Comon Name'); diff --git a/lib/Command/Developer/Reset.php b/lib/Command/Developer/Reset.php index e93c2e52f8..cd48952c22 100644 --- a/lib/Command/Developer/Reset.php +++ b/lib/Command/Developer/Reset.php @@ -149,7 +149,8 @@ private function resetNotifications(string $user): void { $delete->andWhere($delete->expr()->eq('user', $delete->createNamedParameter($user))); } $delete->executeStatement(); - } catch (\Throwable $e) { + } catch (\Throwable) { + // TODO: Add the exception } } @@ -158,7 +159,8 @@ private function resetIdentifyMethods(): void { $delete = $this->db->getQueryBuilder(); $delete->delete('libresign_identify_method') ->executeStatement(); - } catch (\Throwable $e) { + } catch (\Throwable) { + // TODO: Add the exception } } @@ -167,7 +169,8 @@ private function resetSignRequest(): void { $delete = $this->db->getQueryBuilder(); $delete->delete('libresign_sign_request') ->executeStatement(); - } catch (\Throwable $e) { + } catch (\Throwable) { + // TODO: Add the exception } } @@ -176,7 +179,8 @@ private function resetFile(): void { $delete = $this->db->getQueryBuilder(); $delete->delete('libresign_file') ->executeStatement(); - } catch (\Throwable $e) { + } catch (\Throwable) { + // TODO: Add the exception } } @@ -185,7 +189,8 @@ private function resetFileElement(): void { $delete = $this->db->getQueryBuilder(); $delete->delete('libresign_file_element') ->executeStatement(); - } catch (\Throwable $e) { + } catch (\Throwable) { + // TODO: Add the exception } } @@ -194,7 +199,8 @@ private function resetUserElement(): void { $delete = $this->db->getQueryBuilder(); $delete->delete('libresign_user_element') ->executeStatement(); - } catch (\Throwable $e) { + } catch (\Throwable) { + // TODO: Add the exception } } @@ -205,7 +211,8 @@ private function resetConfig(): void { ->where($delete->expr()->eq('appid', $delete->createNamedParameter(Application::APP_ID))) ->andWhere($delete->expr()->notIn('configkey', $delete->createNamedParameter(['enabled', 'installed_version'], IQueryBuilder::PARAM_STR_ARRAY))) ->executeStatement(); - } catch (\Throwable $e) { + } catch (\Throwable) { + // TODO: Add the exception } } } diff --git a/lib/Controller/AEnvironmentPageAwareController.php b/lib/Controller/AEnvironmentPageAwareController.php index a9398619ca..aa3106fc0f 100644 --- a/lib/Controller/AEnvironmentPageAwareController.php +++ b/lib/Controller/AEnvironmentPageAwareController.php @@ -61,7 +61,7 @@ public function loadSignRequestUuid(string $uuid): void { $this->fileEntity = $this->signFileService->getFile( $this->signRequestEntity->getFileId(), ); - } catch (DoesNotExistException $e) { + } catch (DoesNotExistException) { throw new LibresignException(json_encode([ 'action' => JSActions::ACTION_DO_NOTHING, 'errors' => [$this->l10n->t('Invalid UUID')], diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index db88ad3b4b..fd974ff12a 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -274,7 +274,7 @@ public function getSignatureElements(): JSONResponse { ], Http::STATUS_OK ); - } catch (\Throwable $th) { + } catch (\Throwable) { return new JSONResponse( [ 'message' => $this->l10n->t('Elements not found') @@ -293,7 +293,7 @@ public function getSignatureElement($elementId): JSONResponse { $this->accountService->getUserElementByElementId($userId, $elementId), Http::STATUS_OK ); - } catch (\Throwable $th) { + } catch (\Throwable) { return new JSONResponse( [ 'message' => $this->l10n->t('Element not found') @@ -338,7 +338,7 @@ public function deleteSignatureElement($elementId): JSONResponse { $userId = $this->userSession->getUser()->getUID(); try { $this->accountService->deleteSignatureElement($userId, $elementId); - } catch (\Throwable $th) { + } catch (\Throwable) { return new JSONResponse( [ 'message' => $this->l10n->t('Element not found') diff --git a/lib/Controller/FileController.php b/lib/Controller/FileController.php index db676220ae..280385bd2a 100644 --- a/lib/Controller/FileController.php +++ b/lib/Controller/FileController.php @@ -138,7 +138,7 @@ public function list($page = null, $length = null): JSONResponse { #[NoCSRFRequired] public function getPage(string $uuid, int $page) { try { - $page = $this->fileService->getPage($uuid, $page, $this->userSession->getUser()->getUID()); + $page = $this->fileService->getPage($uuid, $page); return new DataDisplayResponse( $page, Http::STATUS_OK, diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index f309447055..0da4d33d20 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -87,7 +87,7 @@ public function index(): TemplateResponse { try { $this->validateHelper->canRequestSign($this->userSession->getUser()); $this->initialState->provideInitialState('can_request_sign', true); - } catch (LibresignException $th) { + } catch (LibresignException) { $this->initialState->provideInitialState('can_request_sign', false); } @@ -156,7 +156,7 @@ public function signAccountFile($uuid): TemplateResponse { try { $fileEntity = $this->signFileService->getFileByUuid($uuid); $this->signFileService->getAccountFileById($fileEntity->getId()); - } catch (DoesNotExistException $e) { + } catch (DoesNotExistException) { $config = [ 'action' => JSActions::ACTION_DO_NOTHING, 'errors' => [$this->l10n->t('Invalid UUID')], @@ -190,7 +190,7 @@ public function getPdf($uuid) { $this->throwIfValidationPageNotAccessible(); try { $file = $this->accountService->getPdfByUuid($uuid); - } catch (DoesNotExistException $th) { + } catch (DoesNotExistException) { return new DataResponse([], Http::STATUS_NOT_FOUND); } @@ -321,7 +321,7 @@ public function validationFile(string $uuid): TemplateResponse { try { $fileEntity = $this->signFileService->getFileByUuid($uuid); $this->signFileService->getAccountFileById($fileEntity->getId()); - } catch (DoesNotExistException $e) { + } catch (DoesNotExistException) { $config = [ 'action' => JSActions::ACTION_DO_NOTHING, 'errors' => [$this->l10n->t('Invalid UUID')], diff --git a/lib/Controller/SignFileController.php b/lib/Controller/SignFileController.php index 8c48fa713f..d8d821ba9f 100644 --- a/lib/Controller/SignFileController.php +++ b/lib/Controller/SignFileController.php @@ -167,7 +167,7 @@ private function getCode(string $uuid = null, int $fileId = null): JSONResponse } else { $signRequest = $this->signRequestMapper->getByUuidAndUserId($uuid, $user->getUID()); } - } catch (\Throwable $th) { + } catch (\Throwable) { throw new LibresignException($this->l10n->t('Invalid data to sign file'), 1); } $this->validateHelper->canRequestCode($signRequest); @@ -175,7 +175,7 @@ private function getCode(string $uuid = null, int $fileId = null): JSONResponse $this->validateHelper->fileCanBeSigned($libreSignFile); $this->signFileService->requestCode($signRequest, $user); $message = $this->l10n->t('The code to sign file was successfully requested.'); - } catch (SmsTransmissionException $e) { + } catch (SmsTransmissionException) { // There was an error when to send SMS code to user. $message = $this->l10n->t('Failed to send code.'); $statusCode = Http::STATUS_UNPROCESSABLE_ENTITY; diff --git a/lib/Db/AccountFileMapper.php b/lib/Db/AccountFileMapper.php index 8424b5ac44..4b6e991705 100644 --- a/lib/Db/AccountFileMapper.php +++ b/lib/Db/AccountFileMapper.php @@ -113,7 +113,7 @@ public function accountFileList(array $filter, int $page = null, int $length = n return $return; } - private function getUserAccountFile(array $filter = [], bool $count = false): Pagination { + private function getUserAccountFile(array $filter = []): Pagination { $qb = $this->db->getQueryBuilder(); $qb->select( 'f.id', @@ -236,7 +236,6 @@ private function formatListRow(array $row, string $url): array { */ private function assocFileToSignRequestAndFormat(array $files, array $signers): array { foreach ($files as $key => $file) { - $totalSigned = 0; $files[$key]['file']['signers'] = []; foreach ($signers as $signerKey => $signer) { if ($signer->getFileId() === $file['id']) { @@ -256,7 +255,6 @@ private function assocFileToSignRequestAndFormat(array $files, array $signers): $data['sign_date'] = (new \DateTime()) ->setTimestamp($signer->getSigned()) ->format('Y-m-d H:i:s'); - $totalSigned++; } $files[$key]['file']['signers'][] = $data; unset($signers[$signerKey]); diff --git a/lib/Db/UserElementMapper.php b/lib/Db/UserElementMapper.php index cb949085bc..893519d7f0 100644 --- a/lib/Db/UserElementMapper.php +++ b/lib/Db/UserElementMapper.php @@ -70,7 +70,7 @@ public function findOne(array $data): UserElement { $qb = $this->getQueryBuilder($data); try { $row = $this->findOneQuery($qb); - } catch (\Throwable $th) { + } catch (\Throwable) { $qb->andWhere( $qb->expr()->eq('ue.starred', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT)) ); diff --git a/lib/Files/TemplateLoader.php b/lib/Files/TemplateLoader.php index f954f58de4..39f6ac8d75 100644 --- a/lib/Files/TemplateLoader.php +++ b/lib/Files/TemplateLoader.php @@ -70,7 +70,7 @@ public function handle(Event $event): void { try { $this->validateHelper->canRequestSign($this->userSession->getUser()); $this->initialState->provideInitialState('can_request_sign', true); - } catch (LibresignException $th) { + } catch (LibresignException) { $this->initialState->provideInitialState('can_request_sign', false); } } diff --git a/lib/Handler/CertificateEngine/AEngineHandler.php b/lib/Handler/CertificateEngine/AEngineHandler.php index eed2f2f879..2dc6fa7a19 100644 --- a/lib/Handler/CertificateEngine/AEngineHandler.php +++ b/lib/Handler/CertificateEngine/AEngineHandler.php @@ -95,7 +95,7 @@ public function generateCertificate(string $certificate, string $privateKey): st if (!$certContent) { throw new \Exception(); } - } catch (\Throwable $th) { + } catch (\Throwable) { throw new LibresignException('Error while creating certificate file', 500); } @@ -176,7 +176,7 @@ public function getConfigPath(): string { if (!$folder->fileExists('/')) { throw new \Exception(); } - } catch (\Throwable $th) { + } catch (\Throwable) { $folder = $this->appData->newFolder($this->getName() . '_config'); } $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/'); diff --git a/lib/Handler/CertificateEngine/CfsslHandler.php b/lib/Handler/CertificateEngine/CfsslHandler.php index 9387733ab9..fc136ff0a6 100644 --- a/lib/Handler/CertificateEngine/CfsslHandler.php +++ b/lib/Handler/CertificateEngine/CfsslHandler.php @@ -180,7 +180,8 @@ private function portOpen(): bool { $port = parse_url($this->getCfsslUri(), PHP_URL_PORT); try { $socket = fsockopen($host, $port, $errno, $errstr, 0.1); - } catch (\Throwable $th) { + } catch (\Throwable) { + // TODO: Add the exception } if (isset($socket) && is_resource($socket)) { fclose($socket); @@ -283,7 +284,8 @@ public function isSetupOk(): bool { try { $this->getClient(); return true; - } catch (\Throwable $th) { + } catch (\Throwable) { + // TODO: Add the exception } return false; } diff --git a/lib/Handler/CertificateEngine/OpenSslHandler.php b/lib/Handler/CertificateEngine/OpenSslHandler.php index 7670c1a394..604376400a 100644 --- a/lib/Handler/CertificateEngine/OpenSslHandler.php +++ b/lib/Handler/CertificateEngine/OpenSslHandler.php @@ -62,7 +62,7 @@ public function generateRootCert( } $csr = openssl_csr_new($dn, $privkey, array('digest_alg' => 'sha256')); - $x509 = openssl_csr_sign($csr, null, $privkey, $days = 365 * 5, array('digest_alg' => 'sha256')); + $x509 = openssl_csr_sign($csr, null, $privkey, 365 * 5, array('digest_alg' => 'sha256')); openssl_csr_export($csr, $csrout); openssl_x509_export($x509, $certout); diff --git a/lib/Handler/Pkcs12Handler.php b/lib/Handler/Pkcs12Handler.php index 82f973dbf8..c8c0117d95 100644 --- a/lib/Handler/Pkcs12Handler.php +++ b/lib/Handler/Pkcs12Handler.php @@ -86,7 +86,8 @@ public function deletePfx(string $uid): void { try { $file = $folder->get($this->pfxFilename); $file->delete(); - } catch (\Throwable $th) { + } catch (\Throwable) { + // TODO: Add the exception } } diff --git a/lib/Helper/ValidateHelper.php b/lib/Helper/ValidateHelper.php index 5dd303d823..4d2e6b3897 100644 --- a/lib/Helper/ValidateHelper.php +++ b/lib/Helper/ValidateHelper.php @@ -93,7 +93,7 @@ public function validateNewFile(array $data): void { $userFolder = $this->root->getUserFolder($data['userManager']->getUID()); try { $node = $userFolder->get($data['file']['path']); - } catch (NotFoundException $e) { + } catch (NotFoundException) { throw new LibresignException($this->l10n->t('Invalid data to validate file'), 404); } $this->validateNotRequestedSign($node->getId()); @@ -135,7 +135,7 @@ public function validateFile(array $data, int $type = self::TYPE_TO_SIGN): void $userFolder = $this->root->getUserFolder($data['userManager']->getUID()); try { $userFolder->get($data['file']['path']); - } catch (NotFoundException $e) { + } catch (NotFoundException) { throw new LibresignException($this->l10n->t('Invalid data to validate file'), 404); } } else { @@ -185,7 +185,8 @@ public function validateBase64(string $base64, int $type = self::TYPE_TO_SIGN): public function validateNotRequestedSign(int $nodeId): void { try { $fileMapper = $this->signRequestMapper->getByNodeId($nodeId); - } catch (\Throwable $th) { + } catch (\Throwable) { + // TODO: Add the exception } if (!empty($fileMapper)) { throw new LibresignException($this->l10n->t('Already asked to sign this document')); @@ -218,7 +219,7 @@ public function validateElementSignRequestId(array $element, int $type): void { } try { $this->signRequestMapper->getById($element['signRequestId']); - } catch (\Throwable $th) { + } catch (\Throwable) { throw new LibresignException($this->l10n->t('User not found for element.')); } } @@ -282,14 +283,14 @@ public function validateVisibleElementsRelation(array $list, SignRequest $signRe $this->validateUserIsOwnerOfPdfVisibleElement($elements['documentElementId'], $user->getUID()); try { $this->userElementMapper->findOne(['id' => $elements['profileElementId'], 'user_id' => $user->getUID()]); - } catch (\Throwable $th) { + } catch (\Throwable) { throw new LibresignException($this->l10n->t('Field %s does not belong to user', $elements['profileElementId'])); } } - $this->validateUserHasNecessaryElements($signRequest, $user, $list); + $this->validateUserHasNecessaryElements($signRequest, $list); } - private function validateUserHasNecessaryElements(SignRequest $signRequest, IUser $user, array $list = []): void { + private function validateUserHasNecessaryElements(SignRequest $signRequest, array $list = []): void { $fileElements = $this->fileElementMapper->getByFileIdAndSignRequestId($signRequest->getFileId(), $signRequest->getId()); $total = array_filter($fileElements, function (FileElement $fileElement) use ($list, $signRequest): bool { $found = array_filter($list, function ($item) use ($fileElement): bool { @@ -302,7 +303,7 @@ private function validateUserHasNecessaryElements(SignRequest $signRequest, IUse 'type' => $fileElement->getType(), ]); return true; - } catch (\Throwable $th) { + } catch (\Throwable) { throw new LibresignException($this->l10n->t('You need to define a visible signature or initials to sign this document.')); } } @@ -321,7 +322,7 @@ public function validateUserIsOwnerOfPdfVisibleElement(int $documentElementId, s if ($file->getUserId() !== $uid) { throw new LibresignException($this->l10n->t('Field %s does not belong to user', $documentElementId)); } - } catch (\Throwable $th) { + } catch (\Throwable) { ($signRequest->getFileId()); throw new LibresignException($this->l10n->t('Field %s does not belong to user', $documentElementId)); } @@ -330,7 +331,7 @@ public function validateUserIsOwnerOfPdfVisibleElement(int $documentElementId, s public function validateAccountFileIsOwnedByUser(int $nodeId, string $uid): void { try { $this->accountFileMapper->getByUserIdAndNodeId($uid, $nodeId); - } catch (\Throwable $th) { + } catch (\Throwable) { throw new LibresignException($this->l10n->t('This file is not yours')); } } @@ -354,7 +355,7 @@ public function validateIfNodeIdExists(int $nodeId, int $type = self::TYPE_TO_SI try { $file = $this->root->getById($nodeId); $file = $file[0] ?? null; - } catch (\Throwable $th) { + } catch (\Throwable) { throw new LibresignException($this->l10n->t('File type: %s. Invalid fileID.', [$this->getTypeOfFile($type)])); } if (!$file) { @@ -391,7 +392,7 @@ public function validateMimeTypeAcceptedByMime(string $mimetype, int $type = sel public function validateLibreSignNodeId(int $nodeId): void { try { $this->getLibreSignFileByNodeId($nodeId); - } catch (\Throwable $th) { + } catch (\Throwable) { throw new LibresignException($this->l10n->t('Invalid fileID')); } } @@ -463,7 +464,8 @@ public function validateFileStatus(array $data): void { } elseif (!empty($data['file']['fileId'])) { try { $file = $this->fileMapper->getByFileId($data['file']['fileId']); - } catch (\Throwable $th) { + } catch (\Throwable) { + // TODO: Add the exception } } if (isset($file)) { @@ -524,7 +526,7 @@ public function haveValidMail(array $data, ?int $type = null): void { public function signerWasAssociated(array $signer): void { try { $libresignFile = $this->fileMapper->getByFileId(); - } catch (\Throwable $th) { + } catch (\Throwable) { throw new LibresignException($this->l10n->t('File not loaded')); } $signatures = $this->signRequestMapper->getByFileUuid($libresignFile->getUuid()); @@ -548,7 +550,7 @@ public function signerWasAssociated(array $signer): void { public function notSigned(array $signer): void { try { $libresignFile = $this->fileMapper->getByFileId(); - } catch (\Throwable $th) { + } catch (\Throwable) { throw new LibresignException($this->l10n->t('File not loaded')); } $signatures = $this->signRequestMapper->getByFileUuid($libresignFile->getUuid()); @@ -578,7 +580,7 @@ public function notSigned(array $signer): void { public function validateFileUuid(array $data): void { try { $this->fileMapper->getByUuid($data['uuid']); - } catch (\Throwable $th) { + } catch (\Throwable) { throw new LibresignException($this->l10n->t('Invalid UUID file')); } } @@ -602,7 +604,7 @@ private function validateSignerUuidExists(string $uuid): void { try { $signRequest = $this->signRequestMapper->getByUuid($uuid); $this->fileMapper->getById($signRequest->getFileId()); - } catch (DoesNotExistException $e) { + } catch (DoesNotExistException) { throw new LibresignException(json_encode([ 'action' => JSActions::ACTION_DO_NOTHING, 'errors' => [$this->l10n->t('Invalid UUID')], @@ -613,7 +615,7 @@ private function validateSignerUuidExists(string $uuid): void { public function validateIsSignerOfFile(int $signRequestId, int $fileId): void { try { $this->signRequestMapper->getByFileIdAndSignRequestId($fileId, $signRequestId); - } catch (\Throwable $th) { + } catch (\Throwable) { throw new LibresignException($this->l10n->t('Signer not associated to this file')); } } @@ -621,7 +623,8 @@ public function validateIsSignerOfFile(int $signRequestId, int $fileId): void { public function validateUserHasNoFileWithThisType(string $uid, string $type): void { try { $exists = $this->accountFileMapper->getByUserAndType($uid, $type); - } catch (\Throwable $th) { + } catch (\Throwable) { + // TODO: Add the exception } if (!empty($exists)) { throw new LibresignException($this->l10n->t('A file of this type has been associated.')); diff --git a/lib/Middleware/InjectionMiddleware.php b/lib/Middleware/InjectionMiddleware.php index 04a2c252d9..e10406d9ea 100644 --- a/lib/Middleware/InjectionMiddleware.php +++ b/lib/Middleware/InjectionMiddleware.php @@ -127,13 +127,11 @@ private function requireSigner(): void { } /** - * @param Controller $controller - * @param string $methodName * @param \Exception $exception - * @throws \Exception * @return Response + *@throws \Exception */ - public function afterException($controller, $methodName, \Exception $exception): Response { + public function afterException(\Exception $exception): Response { switch (true) { case $exception instanceof LibresignException: if ($this->isJson($exception->getMessage())) { diff --git a/lib/Migration/Version8000Date20230410230327.php b/lib/Migration/Version8000Date20230410230327.php index 98d9bb77fb..3f06663905 100644 --- a/lib/Migration/Version8000Date20230410230327.php +++ b/lib/Migration/Version8000Date20230410230327.php @@ -52,7 +52,8 @@ public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array try { $folder = $appFolder->getFolder('libresign-cli'); $folder->delete(); - } catch (NotFoundException $e) { + } catch (NotFoundException) { + // TODO: Add the exception } $this->config->deleteAppValue(Application::APP_ID, 'libresign_cli_path'); } diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index f2f76e6012..92bf17628e 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -77,7 +77,7 @@ private function parseSignRequest( $parameters = $notification->getSubjectParameters(); try { $signRequest = $this->signRequestMapper->getById($parameters['signRequest']); - } catch (DoesNotExistException $th) { + } catch (DoesNotExistException) { throw new \InvalidArgumentException(); } $notification diff --git a/lib/Service/AccountService.php b/lib/Service/AccountService.php index 9288dc407f..b8be4dac40 100644 --- a/lib/Service/AccountService.php +++ b/lib/Service/AccountService.php @@ -106,7 +106,7 @@ public function validateCreateToSign(array $data): void { } try { $signRequest = $this->getSignRequestByUuid($data['uuid']); - } catch (\Throwable $th) { + } catch (\Throwable) { throw new LibresignException($this->l10n->t('UUID not found'), 1); } $identifyMethods = $this->identifyMethodService->getIdentifyMethodsFromSignRequestId($signRequest->getId()); @@ -226,7 +226,7 @@ public function createToSign(string $uuid, string $email, string $password, ?str try { $emailTemplate = $this->newUserMail->generateTemplate($newUser, false); $this->newUserMail->sendMail($newUser, $emailTemplate); - } catch (\Exception $e) { + } catch (\Exception) { throw new LibresignException('Unable to send the invitation', 1); } } @@ -274,7 +274,8 @@ public function hasSignatureFile(?IUser $user = null): bool { try { $this->pkcs12Handler->getPfx($user->getUID()); return true; - } catch (\Throwable $th) { + } catch (\Throwable) { + // TODO: Add the exception } return false; } @@ -296,7 +297,7 @@ public function getPdfByUuid(string $uuid): File { } $mountsContainingFile = $this->userMountCache->getMountsForFileId($nodeId); foreach ($mountsContainingFile as $fileInfo) { - $nodes = $this->root->getByIdInPath($nodeId, $fileInfo->getMountPoint()); + $this->root->getByIdInPath($nodeId, $fileInfo->getMountPoint()); } $nodes = $this->root->getById($nodeId); if (empty($nodes)) { @@ -460,7 +461,7 @@ public function getUserElements(string $userId): array { private function signatureFileExists(UserElement $userElement): bool { try { $this->folderService->getFolder($userElement->getFileId()); - } catch (\Exception $e) { + } catch (\Exception) { $this->userElementMapper->delete($userElement); return false; } @@ -540,8 +541,8 @@ public function deletePfx(IUser $user): void { */ public function updatePfxPassword(IUser $user, string $current, string $new): void { try { - $pfx = $this->pkcs12Handler->updatePassword($user->getUID(), $current, $new); - } catch (InvalidPasswordException $e) { + $this->pkcs12Handler->updatePassword($user->getUID(), $current, $new); + } catch (InvalidPasswordException) { throw new LibresignException($this->l10n->t('Invalid user or password')); } } diff --git a/lib/Service/ConfigureCheckService.php b/lib/Service/ConfigureCheckService.php index 58d13f65bc..7540e9171a 100644 --- a/lib/Service/ConfigureCheckService.php +++ b/lib/Service/ConfigureCheckService.php @@ -304,7 +304,7 @@ function (ConfigureCheckHelper $config) { public function checkCertificate(): array { try { $return = $this->certificateEngine->getEngine()->configureCheck(); - } catch (\Throwable $th) { + } catch (\Throwable) { $return = [ (new ConfigureCheckHelper()) ->setErrorMessage('Define the certificate engine to use') diff --git a/lib/Service/FileService.php b/lib/Service/FileService.php index b390159a8f..3259b2f7bc 100644 --- a/lib/Service/FileService.php +++ b/lib/Service/FileService.php @@ -164,7 +164,7 @@ public function setFileByType(string $type, $identifier): self { [$this->fileMapper, 'getBy' . $type], $identifier ); - } catch (\Throwable $th) { + } catch (\Throwable) { throw new LibresignException($this->l10n->t('Invalid data to validate file'), 404); } if (!$file) { @@ -294,7 +294,8 @@ private function getVisibleElements(): array { ); $return[] = $element; } - } catch (\Throwable $th) { + } catch (\Throwable) { + // TODO: Add the exception } return $return; } @@ -424,7 +425,7 @@ public function formatFile(): array { return $return; } - public function getPage(string $uuid, int $page, string $uid): string { + public function getPage(string $uuid, int $page): string { $libreSignFile = $this->fileMapper->getByUuid($uuid); $uid = $this->userSession->getUser()->getUID(); if ($libreSignFile->getUserId() !== $uid) { diff --git a/lib/Service/FolderService.php b/lib/Service/FolderService.php index 59d3058dae..4fbb6d6f8e 100644 --- a/lib/Service/FolderService.php +++ b/lib/Service/FolderService.php @@ -156,7 +156,7 @@ public function getFileByPath(string $path): Node { $userFolder = $this->root->getUserFolder($this->getUserId()); try { return $userFolder->get($path); - } catch (NotFoundException $e) { + } catch (NotFoundException) { throw new LibresignException($this->l10n->t('Invalid data to validate file'), 404); } } diff --git a/lib/Service/IdentifyMethod/Email.php b/lib/Service/IdentifyMethod/Email.php index 054e9517e1..df9820c33d 100644 --- a/lib/Service/IdentifyMethod/Email.php +++ b/lib/Service/IdentifyMethod/Email.php @@ -89,7 +89,7 @@ public function validateToSign(?IUser $user = null): void { } private function validateWithEmail(IUser $user): void { - $signer = $this->getSignerFromEmail($user); + $this->getSignerFromEmail($user); $this->throwIfAlreadySigned(); $this->throwIfFileNotFound(); } diff --git a/lib/Service/IdentifyMethodService.php b/lib/Service/IdentifyMethodService.php index 1913e2832b..b1cd3788ee 100644 --- a/lib/Service/IdentifyMethodService.php +++ b/lib/Service/IdentifyMethodService.php @@ -163,12 +163,12 @@ public function save(SignRequest $signRequest, bool $notify = true): void { $entity = $identifyMethod->getEntity(); $entity->setSignRequestId($signRequest->getId()); if ($entity->getId()) { - $entity = $this->identifyMethodMapper->update($entity); + $this->identifyMethodMapper->update($entity); if ($notify) { $identifyMethod->notify(false, $signRequest); } } else { - $entity = $this->identifyMethodMapper->insert($entity); + $this->identifyMethodMapper->insert($entity); if ($notify) { $identifyMethod->notify(true, $signRequest); } diff --git a/lib/Service/InstallService.php b/lib/Service/InstallService.php index 5cb3289f4c..81d1663354 100644 --- a/lib/Service/InstallService.php +++ b/lib/Service/InstallService.php @@ -92,7 +92,7 @@ private function getFolder(string $path = ''): ISimpleFolder { if ($path) { try { $folder = $folder->getFolder($path); - } catch (\Throwable $th) { + } catch (\Throwable) { $folder = $folder->newFolder($path); } } @@ -176,7 +176,7 @@ private function setCache(string $key, $value): void { $appFolder = $this->getFolder(); try { $file = $appFolder->getFile('setup-cache.json'); - } catch (\Throwable $th) { + } catch (\Throwable) { $file = $appFolder->newFile('setup-cache.json', '[]'); } $json = $file->getContent() ? json_decode($file->getContent(), true) : []; @@ -197,7 +197,8 @@ private function getCache(string $key) { $file = $appFolder->getFile('setup-cache.json'); $json = $file->getContent() ? json_decode($file->getContent(), true) : []; return $json[$key] ?? null; - } catch (\Throwable $th) { + } catch (\Throwable) { + // TODO: Add the exception } return; } @@ -210,7 +211,8 @@ private function removeCache(string $key): void { try { $file = $appFolder->getFile('setup-cache.json'); $file->delete(); - } catch (\Throwable $th) { + } catch (\Throwable) { + // TODO: Add the exception } return; } @@ -259,7 +261,7 @@ public function isDownloadWip(): bool { if (!count($progressData)) { continue; } - exec('ps -p ' . $progressData['pid'], $output, $exitCode); + exec('ps -p ' . $progressData['pid'], $output); if (count($output) <= 1) { $this->removeDownloadProgress(); return false; @@ -309,7 +311,7 @@ public function installJava(?bool $async = false): void { $hash = $this->getHash($folder, 'java', $compressedFileName, self::JAVA_PARTIAL_VERSION, $checksumUrl); try { $compressedFile = $javaFolder->getFile($compressedFileName); - } catch (NotFoundException $th) { + } catch (NotFoundException) { $compressedFile = $javaFolder->newFile($compressedFileName); } $comporessedInternalFileName = $this->getDataDir() . DIRECTORY_SEPARATOR . $this->getInternalPathOfFile($compressedFile); @@ -340,7 +342,8 @@ public function uninstallJava(): void { try { $javaFolder = $appFolder->getFolder('/libresign/java'); $javaFolder->delete(); - } catch (NotFoundException $th) { + } catch (NotFoundException) { + // TODO: Add the exception } $this->config->deleteAppValue(Application::APP_ID, 'java_path'); } @@ -359,7 +362,7 @@ public function installJSignPdf(?bool $async = false): void { $compressedFileName = 'jsignpdf-' . JSignPdfHandler::VERSION . '.zip'; try { $compressedFile = $this->getFolder()->getFile($compressedFileName); - } catch (\Throwable $th) { + } catch (\Throwable) { $compressedFile = $this->getFolder()->newFile($compressedFileName); } $comporessedInternalFileName = $this->getDataDir() . DIRECTORY_SEPARATOR . $this->getInternalPathOfFile($compressedFile); @@ -391,7 +394,8 @@ public function uninstallJSignPdf(): void { try { $folder = $appFolder->getFolder($path); $folder->delete(); - } catch (NotFoundException $e) { + } catch (NotFoundException) { + // TODO: Add the exception } $this->config->deleteAppValue(Application::APP_ID, 'jsignpdf_jar_path'); } @@ -405,7 +409,7 @@ public function installPdftk(?bool $async = false): void { try { $file = $this->getFolder()->getFile('pdftk'); - } catch (\Throwable $th) { + } catch (\Throwable) { $file = $this->getFolder()->newFile('pdftk'); } $fullPath = $this->getDataDir() . DIRECTORY_SEPARATOR . $this->getInternalPathOfFile($file); @@ -433,7 +437,8 @@ public function uninstallPdftk(): void { try { $file = $appFolder->getFile($path); $file->delete(); - } catch (NotFoundException $e) { + } catch (NotFoundException) { + // TODO: Add the exception } $this->config->deleteAppValue(Application::APP_ID, 'pdftk_path'); } @@ -495,7 +500,7 @@ private function installCfsslArm(): void { $appFolder = $this->getFolder(); try { $cfsslFolder = $appFolder->getFolder('cfssl'); - } catch (NotFoundException $th) { + } catch (NotFoundException) { $cfsslFolder = $appFolder->newFolder('cfssl'); } $compressedFileName = 'cfssl-' . self::CFSSL_VERSION . '-1-aarch64.pkg.tar.xz'; @@ -504,7 +509,7 @@ private function installCfsslArm(): void { $hash = '944a6c54e53b0e2ef04c9b22477eb5f637715271c74ccea9bb91d7ac0473b855'; try { $compressedFile = $cfsslFolder->getFile($compressedFileName); - } catch (NotFoundException $th) { + } catch (NotFoundException) { $compressedFile = $cfsslFolder->newFile($compressedFileName); } @@ -538,7 +543,8 @@ public function uninstallCfssl(): void { try { $folder = $appFolder->getFolder($path); $folder->delete(); - } catch (NotFoundException $e) { + } catch (NotFoundException) { + // TODO: Add the exception } $this->config->deleteAppValue(Application::APP_ID, 'cfssl_bin'); } @@ -616,7 +622,7 @@ private function getHash(ISimpleFolder $folder, string $type, string $file, stri $hashFileName = 'checksums_' . $type . '_' . $version . '.txt'; try { $fileObject = $folder->getFile($hashFileName); - } catch (NotFoundException $th) { + } catch (NotFoundException) { $hashes = file_get_contents($checksumUrl); if (!$hashes) { throw new LibresignException('Failute to download hash file. URL: ' . $checksumUrl); @@ -625,7 +631,8 @@ private function getHash(ISimpleFolder $folder, string $type, string $file, stri } try { $hashes = $fileObject->getContent(); - } catch (\Throwable $th) { + } catch (\Throwable) { + // TODO: Add the exception } if (empty($hashes)) { throw new LibresignException( diff --git a/lib/Service/NotifyService.php b/lib/Service/NotifyService.php index d5635f6025..cacb88f437 100644 --- a/lib/Service/NotifyService.php +++ b/lib/Service/NotifyService.php @@ -65,7 +65,7 @@ public function signers(int $nodeId, array $signers): void { private function notify(SignRequest $signRequest, array $signers = []): void { $identifyMethods = $this->identifyMethodService->getIdentifyMethodsFromSignRequestId($signRequest->getId()); - foreach ($identifyMethods as $methodName => $instances) { + foreach ($identifyMethods as $instances) { $identifyMethod = array_reduce($instances, function (?IIdentifyMethod $carry, IIdentifyMethod $identifyMethod) use ($signers): ?IIdentifyMethod { foreach ($signers as $signer) { $key = key($signer); diff --git a/lib/Service/RequestSignatureService.php b/lib/Service/RequestSignatureService.php index 03decf9515..e04371c561 100644 --- a/lib/Service/RequestSignatureService.php +++ b/lib/Service/RequestSignatureService.php @@ -96,7 +96,8 @@ public function saveFile(array $data): FileEntity { return $this->fileMapper->update($file); } return $file; - } catch (\Throwable $th) { + } catch (\Throwable) { + // TODO: Add the exception } } @@ -265,7 +266,7 @@ private function setDataToUser(SignRequestEntity $signRequest, array $user, int private function getSignRequestByIdentifyMethod(IIdentifyMethod $identifyMethod, int $fileId): SignRequestEntity { try { $signRequest = $this->signRequestMapper->getByIdentifyMethodAndFileId($identifyMethod, $fileId); - } catch (DoesNotExistException $e) { + } catch (DoesNotExistException) { $signRequest = new SignRequestEntity(); } return $signRequest; @@ -285,7 +286,8 @@ public function unassociateToUser(int $fileId, int $signRequestId): void { foreach ($visibleElements as $visibleElement) { $this->fileElementMapper->delete($visibleElement); } - } catch (\Throwable $th) { + } catch (\Throwable) { + // TODO: Add the exception } } diff --git a/lib/Service/SignFileService.php b/lib/Service/SignFileService.php index 987354d19d..7bed345b76 100644 --- a/lib/Service/SignFileService.php +++ b/lib/Service/SignFileService.php @@ -239,7 +239,7 @@ public function setVisibleElements(array $list): self { throw new \Exception('empty'); } $node = $node[0]; - } catch (\Throwable $th) { + } catch (\Throwable) { throw new LibresignException($this->l10n->t('You need to define a visible signature or initials to sign this document.')); } $tempFile = $this->tempManager->getTemporaryFile('.png'); @@ -324,13 +324,13 @@ private function getPfxFile(): string { $this->friendlyName, true ); - } catch (TypeError $e) { + } catch (TypeError) { throw new LibresignException($this->l10n->t('Failure to generate certificate')); - } catch (EmptyRootCertificateException $e) { + } catch (EmptyRootCertificateException) { throw new LibresignException($this->l10n->t('Empty root certificate data')); - } catch (InvalidArgumentException $e) { + } catch (InvalidArgumentException) { throw new LibresignException($this->l10n->t('Invalid data to generate certificate')); - } catch (\Throwable $th) { + } catch (\Throwable) { throw new LibresignException($this->l10n->t('Failure on generate certificate')); } } @@ -378,7 +378,7 @@ public function getLibresignFile(?int $fileId, ?string $signRequestUuid = null): } else { throw new \Exception('Invalid arguments'); } - } catch (DoesNotExistException $th) { + } catch (DoesNotExistException) { throw new LibresignException($this->l10n->t('File not found'), 1); } return $libresignFile; @@ -420,10 +420,10 @@ public function getSignRequestToSign(FileEntity $libresignFile, IUser $user): Si if ($signRequest->getSigned()) { throw new LibresignException($this->l10n->t('File already signed by you'), 1); } - } catch (DoesNotExistException $th) { + } catch (DoesNotExistException) { try { - $accountFile = $this->accountFileMapper->getByFileId($libresignFile->getId()); - } catch (\Throwable $th) { + $this->accountFileMapper->getByFileId($libresignFile->getId()); + } catch (\Throwable) { throw new LibresignException($this->l10n->t('Invalid data to sign file'), 1); } $this->validateHelper->userCanApproveValidationDocuments($user); @@ -573,7 +573,7 @@ public function getInfoOfFileToSignUsingFileUuid(?string $uuid, ?IUser $user, st try { $fileEntity = $this->fileMapper->getByUuid($uuid); $this->accountFileMapper->getByFileId($fileEntity->getId()); - } catch (DoesNotExistException $e) { + } catch (DoesNotExistException) { throw new LibresignException(json_encode([ 'action' => JSActions::ACTION_DO_NOTHING, 'errors' => [$this->l10n->t('Invalid UUID')], @@ -656,7 +656,7 @@ public function getFileUrl(string $format, FileEntity $fileEntity, File $fileToS try { $this->accountFileMapper->getByFileId($fileEntity->getId()); $url = ['url' => $this->urlGenerator->linkToRoute('libresign.page.getPdf', ['uuid' => $uuid])]; - } catch (DoesNotExistException $e) { + } catch (DoesNotExistException) { $url = ['url' => $this->urlGenerator->linkToRoute('libresign.page.getPdfUser', ['uuid' => $uuid])]; } break; diff --git a/tests/Api/Controller/SignFileControllerTest.php b/tests/Api/Controller/SignFileControllerTest.php index 7395f9518c..7291ab3f51 100644 --- a/tests/Api/Controller/SignFileControllerTest.php +++ b/tests/Api/Controller/SignFileControllerTest.php @@ -547,7 +547,7 @@ public function testDeleteSignFileIdSignRequestIdWithSuccess() { * @runInSeparateProcess */ public function testDeleteSignFileIdSignRequestIdWithError() { - $user = $this->createUser('username', 'password'); + $this->createUser('username', 'password'); $this->request ->withMethod('DELETE') @@ -598,7 +598,7 @@ public function testDeleteUsingSignFileIdWithSuccess() { * @runInSeparateProcess */ public function testDeleteUsingSignFileIdWithError() { - $user = $this->createUser('username', 'password'); + $this->createUser('username', 'password'); $this->request ->withMethod('DELETE') diff --git a/tests/Unit/Handler/Pkcs12HandlerTest.php b/tests/Unit/Handler/Pkcs12HandlerTest.php index 36440af189..c877c2940d 100644 --- a/tests/Unit/Handler/Pkcs12HandlerTest.php +++ b/tests/Unit/Handler/Pkcs12HandlerTest.php @@ -3,7 +3,6 @@ use OC\SystemConfig; use OCA\Libresign\Handler\CertificateEngine\CfsslHandler; use OCA\Libresign\Handler\CertificateEngine\Handler as CertificateEngineHandler; -use OCA\Libresign\Handler\CertificateEngine\OpenSslHandler; use OCA\Libresign\Handler\JSignPdfHandler; use OCA\Libresign\Handler\Pkcs12Handler; use OCA\Libresign\Service\FolderService; @@ -21,7 +20,6 @@ final class Pkcs12HandlerTest extends \OCA\Libresign\Tests\Unit\TestCase { private CfsslHandler|MockObject $cfsslHandler; private IL10N|MockObject $l10n; private JSignPdfHandler|MockObject $jSignPdfHandler; - private OpenSslHandler|MockObject $openSslHandler; private CertificateEngineHandler|MockObject $certificateEngineHandler; private array $cfsslHandlerBuffer = []; @@ -112,7 +110,7 @@ public function testGetFooterWithSuccess() { $this->config = $this->createMock(IConfig::class); $this->config ->method('getAppValue') - ->willReturnCallback(function ($appid, $key, $default) { + ->willReturnCallback(function ($key) { switch ($key) { case 'add_footer': return 1; case 'validation_site': return 'http://test.coop'; diff --git a/tests/Unit/Service/AccountServiceTest.php b/tests/Unit/Service/AccountServiceTest.php index 000e76abfb..d2d02435b1 100644 --- a/tests/Unit/Service/AccountServiceTest.php +++ b/tests/Unit/Service/AccountServiceTest.php @@ -330,43 +330,6 @@ public function testValidateCertificateDataWithSuccess() { $this->assertNull($actual); } - private function mockValidateWithSuccess() { - $signRequest = $this->createMock(SignRequest::class); - $signRequest - ->method('__call') - ->withConsecutive( - [$this->equalTo('getId')], - [$this->equalTo('getFileId')], - [$this->equalTo('getUserId')], - [$this->equalTo('getNodeId')], - ) - ->will($this->returnValueMap([ - ['getId', [], 1], - ['getFileId', [], 171], - ['getUserId', [], 'username'], - ['getNodeId', [], 171], - ])); - $libresignFile = $this->createMock(\OCA\Libresign\Db\File::class); - $this->fileMapper - ->method('getById') - ->will($this->returnValue($libresignFile)); - $this->signRequestMapper - ->method('getByUuid') - ->will($this->returnValue($signRequest)); - - $this->root - ->method('getById') - ->will($this->returnValue(['fileToSign'])); - $file = $this->createMock(\OCP\Files\File::class); - $folder = $this->createMock(\OCP\Files\Folder::class); - $folder - ->method('getById') - ->willReturn([$file]); - $this->root - ->method('getUserFolder') - ->willReturn($folder); - } - public function testCreateToSignWithErrorInSendingEmail() { $signRequest = $this->createMock(\OCA\Libresign\Db\SignRequest::class); $signRequest diff --git a/tests/Unit/Service/SignFileServiceTest.php b/tests/Unit/Service/SignFileServiceTest.php index b1c28ebff6..edb52db508 100644 --- a/tests/Unit/Service/SignFileServiceTest.php +++ b/tests/Unit/Service/SignFileServiceTest.php @@ -12,7 +12,6 @@ use OCA\Libresign\Helper\JSActions; use OCA\Libresign\Helper\ValidateHelper; use OCA\Libresign\Service\FolderService; -use OCA\Libresign\Service\IdentifyMethodService; use OCA\Libresign\Service\SignFileService; use OCA\Libresign\Service\SignMethodService; use OCP\EventDispatcher\IEventDispatcher; @@ -51,7 +50,6 @@ final class SignFileServiceTest extends \OCA\Libresign\Tests\Unit\TestCase { private IEventDispatcher|MockObject $eventDispatcher; private IURLGenerator|MockObject $urlGenerator; private SignMethodService|MockObject $signMethod; - private IdentifyMethodService|MockObject $identifyMethod; private IdentifyMethodMapper|MockObject $identifyMethodMapper; private ITempManager|MockObject $tempManager; diff --git a/tests/Unit/TestCase.php b/tests/Unit/TestCase.php index 73b2d8bae5..4cd5c3e38e 100644 --- a/tests/Unit/TestCase.php +++ b/tests/Unit/TestCase.php @@ -168,7 +168,8 @@ public function deleteUserIfExists($username): void { if ($user) { try { $user->delete(); - } catch (\Throwable $th) { + } catch (\Throwable) { + // TODO: Add the exception } } } diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index 3485a644a2..56c108f1e2 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -2,7 +2,6 @@ use Behat\Gherkin\Node\PyStringNode; use Behat\Gherkin\Node\TableNode; -use Behat\Testwork\Hook\Scope\BeforeSuiteScope; use Libresign\NextcloudBehat\NextcloudApiContext; use PHPUnit\Framework\Assert; use rpkamp\Behat\MailhogExtension\Context\OpenedEmailStorageAwareContext; @@ -19,8 +18,8 @@ class FeatureContext extends NextcloudApiContext implements OpenedEmailStorageAw /** * @BeforeSuite */ - public static function beforeSuite(BeforeSuiteScope $scope) { - exec('php ../../../../occ config:system:set debug --value true --type boolean', $output); + public static function beforeSuite() { + exec('php ../../../../occ config:system:set debug --value true --type boolean'); } /** @@ -41,7 +40,7 @@ public static function runCommand($command): void { if (get_current_user() !== $owner['name']) { $fullCommand = 'runuser -u ' . $owner['name'] . ' -- ' . $fullCommand; } - exec($fullCommand, $output); + exec($fullCommand); } public function setOpenedEmailStorage(OpenedEmailStorage $storage): void { @@ -180,7 +179,7 @@ public function iChangeTheFile(TableNode $body): void { } $body = new TableNode($newBody); $this->sendOCSRequest('patch', '/apps/libresign/api/v1/request-signature', $body); - $realResponseArray = json_decode($this->response->getBody()->getContents(), true); + json_decode($this->response->getBody()->getContents(), true); } /**