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

GetPublicKeyService::call()   A

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\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