• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

LibreSign / libresign / 21971817996

13 Feb 2026 02:03AM UTC coverage: 51.426%. First build
21971817996

Pull #6824

github

web-flow
Merge 60946de85 into a1cbae371
Pull Request #6824: fix: signature methods names

215 of 237 new or added lines in 20 files covered. (90.72%)

9017 of 17534 relevant lines covered (51.43%)

6.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

6.67
/lib/Service/IdentifyMethod/SignatureMethod/TwofactorGatewayToken.php
1
<?php
2

3
declare(strict_types=1);
4
/**
5
 * SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
6
 * SPDX-License-Identifier: AGPL-3.0-or-later
7
 */
8

9
namespace OCA\Libresign\Service\IdentifyMethod\SignatureMethod;
10

11
use OCA\Libresign\Service\IdentifyMethod\IdentifyService;
12

13
class TwofactorGatewayToken extends AbstractSignatureMethod implements IToken {
14
        private const VISIBILITY_START = 2;
15
        private const VISIBILITY_END = 2;
16

17
        public function __construct(
18
                protected IdentifyService $identifyService,
19
                protected TokenService $tokenService,
20
        ) {
21
                parent::__construct(
10✔
22
                        $identifyService,
10✔
23
                );
10✔
24
        }
25

26
        #[\Override]
27
        public function validateToSign(): void {
28
                $this->throwIfInvalidToken();
×
29
        }
30

31
        #[\Override]
32
        public function toArray(): array {
33
                $entity = $this->getEntity();
×
34

35
                $identifier = match ($entity->getIdentifierKey()) {
×
36
                        'identifier' => $entity->getIdentifierValue(),
×
37
                        'account' => $this->identifyService->getUserManager()->get($entity->getIdentifierValue())
×
38
                                ?->getEMailAddress() ?? '',
×
39
                        default => '',
×
40
                };
×
41

42
                $code = $entity->getCode();
×
43
                $identifiedAt = $entity->getIdentifiedAtDate();
×
44
                $codeSentByUser = $this->codeSentByUser;
×
45

46
                $hasConfirmCode = !empty($code);
×
47
                $needCode = empty($code)
×
48
                        || empty($identifiedAt)
×
49
                        || empty($codeSentByUser);
×
50

51
                $return = parent::toArray();
×
52
                $return['identifyMethod'] = $entity->getIdentifierKey();
×
53
                $return['needCode'] = $needCode;
×
54
                $return['hasConfirmCode'] = $hasConfirmCode;
×
55
                $return['blurredIdentifier'] = $this->blurIdentifier($identifier);
×
56
                $return['hashOfIdentifier'] = md5($identifier);
×
57
                return $return;
×
58
        }
59

60
        private function blurIdentifier(
61
                string $identifier,
62
                int $visibleStart = self::VISIBILITY_START,
63
                int $visibleEnd = self::VISIBILITY_END,
64
        ): string {
65
                $length = mb_strlen($identifier);
×
66

67
                if ($length <= $visibleStart + $visibleEnd) {
×
68
                        return str_repeat('*', $length);
×
69
                }
70

71
                $start = mb_substr($identifier, 0, $visibleStart);
×
72
                $end = mb_substr($identifier, -$visibleEnd);
×
73

74
                $maskedLength = $length - ($visibleStart + $visibleEnd);
×
75

76
                return $start . str_repeat('*', $maskedLength) . $end;
×
77
        }
78

79
        #[\Override]
80
        public function requestCode(string $identifier, string $method): void {
81
                $signRequestMapper = $this->identifyService->getSignRequestMapper();
×
82
                $signRequest = $signRequestMapper->getById($this->getEntity()->getSignRequestId());
×
83
                $displayName = $signRequest->getDisplayName();
×
84
                if ($identifier === $displayName) {
×
85
                        $displayName = '';
×
86
                }
87
                if ($method === 'email') {
×
88
                        $code = $this->tokenService->sendCodeByEmail($identifier, $displayName);
×
89
                } else {
NEW
90
                        $gatewayName = $this->getGatewayName($method);
×
NEW
91
                        $code = $this->tokenService->sendCodeByGateway($identifier, $gatewayName);
×
92
                }
93
                $this->getEntity()->setCode($code);
×
94
                $this->identifyService->save($this->getEntity());
×
95
        }
96

97
        private function getGatewayName(string $identifyMethod): string {
98
                return match ($identifyMethod) {
NEW
99
                        'whatsapp' => 'gowhatsapp',
×
NEW
100
                        default => strtolower($identifyMethod),
×
101
                };
102
        }
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc