From e425b186d93066cdfc93c582a599a02aa1c86457 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Thu, 11 Dec 2025 19:59:15 -0300 Subject: [PATCH] refactor: centralize file status translations in FileStatus enum - Add getLabel() method to FileStatus enum similar to DocMdpLevel and SignRequestStatus - Simplify FileMapper::getTextOfStatus() to delegate to enum's getLabel() - Improves maintainability by centralizing translations in a single place Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- lib/Db/FileMapper.php | 15 +-------------- lib/Enum/FileStatus.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/Db/FileMapper.php b/lib/Db/FileMapper.php index 1f3f2fda5..1a54438d5 100644 --- a/lib/Db/FileMapper.php +++ b/lib/Db/FileMapper.php @@ -250,20 +250,7 @@ class FileMapper extends QBMapper { if (is_int($status)) { $status = FileStatus::from($status); } - return match ($status) { - // TRANSLATORS Name of the status when document is not a LibreSign file - FileStatus::NOT_LIBRESIGN_FILE => $this->l->t('not LibreSign file'), - // TRANSLATORS Name of the status that the document is still as a draft - FileStatus::DRAFT => $this->l->t('draft'), - // TRANSLATORS Name of the status that the document can be signed - FileStatus::ABLE_TO_SIGN => $this->l->t('available for signature'), - // TRANSLATORS Name of the status when the document has already been partially signed - FileStatus::PARTIAL_SIGNED => $this->l->t('partially signed'), - // TRANSLATORS Name of the status when the document has been completely signed - FileStatus::SIGNED => $this->l->t('signed'), - // TRANSLATORS Name of the status when the document was deleted - FileStatus::DELETED => $this->l->t('deleted'), - }; + return $status->getLabel($this->l); } public function neutralizeDeletedUser(string $userId, string $displayName): void { diff --git a/lib/Enum/FileStatus.php b/lib/Enum/FileStatus.php index 8157c3b63..77f3be81d 100644 --- a/lib/Enum/FileStatus.php +++ b/lib/Enum/FileStatus.php @@ -9,6 +9,8 @@ declare(strict_types=1); namespace OCA\Libresign\Enum; +use OCP\IL10N; + /** * File status enum * @@ -21,4 +23,21 @@ enum FileStatus: int { case PARTIAL_SIGNED = 2; case SIGNED = 3; case DELETED = 4; + + public function getLabel(IL10N $l10n): string { + return match($this) { + // TRANSLATORS Name of the status when document is not a LibreSign file + self::NOT_LIBRESIGN_FILE => $l10n->t('not LibreSign file'), + // TRANSLATORS Name of the status that the document is still as a draft + self::DRAFT => $l10n->t('draft'), + // TRANSLATORS Name of the status that the document can be signed + self::ABLE_TO_SIGN => $l10n->t('available for signature'), + // TRANSLATORS Name of the status when the document has already been partially signed + self::PARTIAL_SIGNED => $l10n->t('partially signed'), + // TRANSLATORS Name of the status when the document has been completely signed + self::SIGNED => $l10n->t('signed'), + // TRANSLATORS Name of the status when the document was deleted + self::DELETED => $l10n->t('deleted'), + }; + } }