Completed
Pull Request — master (#2)
by thomas
01:56
created

GetPublicKeyService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 17
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A call() 0 15 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\Message;
9
use BitWasp\Trezor\Device\UserInput\CurrentPinInputInterface;
10
use BitWasp\TrezorProto\GetPublicKey;
11
use BitWasp\TrezorProto\PinMatrixRequest;
12
use BitWasp\TrezorProto\PublicKey;
13
14
class GetPublicKeyService extends DeviceService
15
{
16 3
    public function call(
17
        Session $session,
18
        CurrentPinInputInterface $currentPinInput,
19
        GetPublicKey $getPublicKey
20
    ): PublicKey {
21 3
        $proto = $session->sendMessage(Message::getPublicKey($getPublicKey));
22 3
        if ($proto instanceof PinMatrixRequest) {
23 1
            $proto = $session->sendMessage($this->provideCurrentPin($proto, $currentPinInput));
24
        }
25
26 3
        if (!($proto instanceof PublicKey)) {
27 1
            throw new \RuntimeException("Unexpected response, expecting PublicKey, got " . get_class($proto));
28
        }
29
30 2
        return $proto;
31
    }
32
}
33