Skip to content

Commit 0565704

Browse files
refactor(FileService): extract signRequestId validation to private method
Extracted the signRequestId type casting and validation logic from mapSignerDetailsToSummary() into a dedicated private method extractValidSignRequestId(). This improves code readability by: - Removing inline validation comment (code is now self-documenting) - Centralizing validation logic in a named method that clearly explains the operation (extracting a valid ID or returning null) - Making the validation testable and reusable - Simplifying the main loop by delegating validation concern The method name clearly conveys intent without requiring explanatory comments. All 178 FileServiceTest assertions pass with no regressions. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent f677f07 commit 0565704

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

lib/Service/FileService.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -640,18 +640,13 @@ private function mapSignerDetailsToSummary(array $signers): array {
640640
continue;
641641
}
642642

643-
// Validate and type-cast signRequestId (required field)
644-
$signRequestId = $signerData['signRequestId'] ?? null;
645-
if (is_int($signRequestId)) {
646-
$typedSignRequestId = $signRequestId;
647-
} elseif (is_string($signRequestId) && ctype_digit($signRequestId)) {
648-
$typedSignRequestId = (int)$signRequestId;
649-
} else {
643+
$signRequestId = $this->extractValidSignRequestId($signerData);
644+
if ($signRequestId === null) {
650645
continue;
651646
}
652647

653648
$summary = [
654-
'signRequestId' => $typedSignRequestId,
649+
'signRequestId' => $signRequestId,
655650
'displayName' => isset($signerData['displayName']) ? (string)$signerData['displayName'] : '',
656651
'email' => isset($signerData['email']) ? (string)$signerData['email'] : '',
657652
'signed' => $signerData['signed'] ?? null,
@@ -669,6 +664,24 @@ private function mapSignerDetailsToSummary(array $signers): array {
669664
return $summaries;
670665
}
671666

667+
/**
668+
* Extracts and type-casts signRequestId from signer data.
669+
* Returns null if signRequestId is missing, null, non-numeric, or cannot be converted.
670+
*/
671+
private function extractValidSignRequestId(array $signerData): ?int {
672+
$signRequestId = $signerData['signRequestId'] ?? null;
673+
674+
if (is_int($signRequestId)) {
675+
return $signRequestId;
676+
}
677+
678+
if (is_string($signRequestId) && ctype_digit($signRequestId)) {
679+
return (int)$signRequestId;
680+
}
681+
682+
return null;
683+
}
684+
672685
private function computeEnvelopeSignersProgress(): void {
673686
if (!$this->file || $this->file->getParentFileId() || empty($this->fileData->signers)) {
674687
return;

0 commit comments

Comments
 (0)