GetAddressService::call()   B
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 22
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 10
cts 10
cp 1
rs 8.6737
c 0
b 0
f 0
cc 5
eloc 9
nc 8
nop 3
crap 5
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;
12
13
class GetAddressService extends DeviceService
14
{
15 6
    public function call(
16
        Session $session,
17
        CurrentPinInputInterface $currentPinInput,
18
        TrezorProto\GetAddress $getAddress
19
    ): TrezorProto\Address {
20
21 6
        $proto = $session->sendMessage(Message::getAddress($getAddress));
22 6
        if ($proto instanceof TrezorProto\PinMatrixRequest) {
23 3
            $proto = $session->sendMessage($this->provideCurrentPin($proto, $currentPinInput));
24
        }
25
26 6
        if ($getAddress->getShowDisplay()) {
27 3
            while ($proto instanceof TrezorProto\ButtonRequest) {
28 3
                $proto = $session->sendMessage($this->confirmWithButton($proto, TrezorProto\ButtonRequestType::ButtonRequest_Other()));
29
            }
30
        }
31
32 5
        if (!($proto instanceof TrezorProto\Address)) {
33 1
            throw new UnexpectedResultException("Unexpected response, expecting Address, got " . get_class($proto));
34
        }
35
36 4
        return $proto;
37
    }
38
}
39