Skip to content

Commit 77b2182

Browse files
refactor: extract shared validation metadata normalizer
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 50b3e43 commit 77b2182

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\Libresign\Service\File;
11+
12+
final class ValidationMetadataNormalizer {
13+
/**
14+
* @param array<string, mixed> $metadata
15+
* @return array<string, mixed>
16+
*/
17+
public static function normalize(array $metadata, string $fileName, int $totalPages): array {
18+
$metadata['p'] = $totalPages;
19+
20+
$extension = pathinfo($fileName, PATHINFO_EXTENSION);
21+
if (!isset($metadata['extension']) || !is_string($metadata['extension']) || trim($metadata['extension']) === '') {
22+
$metadata['extension'] = is_string($extension) && $extension !== '' ? strtolower($extension) : 'pdf';
23+
}
24+
25+
return $metadata;
26+
}
27+
}

0 commit comments

Comments
 (0)