GetPublicKeyService::call()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 4
nop 3
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitWasp\Trezor\Device\Command;
6
7
use BitWasp\Trezor\Bridge\Session;
8
use BitWasp\Trezor\Device\Exception\UnexpectedResultException;
9
use BitWasp\Trezor\Device\Message;
10
use BitWasp\Trezor\Device\UserInput\CurrentPinInputInterface;
11
use BitWasp\TrezorProto\GetPublicKey;
12
use BitWasp\TrezorProto\PinMatrixRequest;
13
use BitWasp\TrezorProto\PublicKey;
14
15
class GetPublicKeyService extends DeviceService
16
{
17 4
    public function call(
18
        Session $session,
19
        CurrentPinInputInterface $currentPinInput,
20
        GetPublicKey $getPublicKey
21
    ): PublicKey {
22 4
        $proto = $session->sendMessage(Message::getPublicKey($getPublicKey));
23 4
        if ($proto instanceof PinMatrixRequest) {
24 2
            $proto = $session->sendMessage($this->provideCurrentPin($proto, $currentPinInput));
25
        }
26
27 3
        if (!($proto instanceof PublicKey)) {
28 1
            throw new UnexpectedResultException("Unexpected response, expecting PublicKey, got " . get_class($proto));
29
        }
30
31 2
        return $proto;
32
    }
33
}
34