GetAddressService   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 24
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B call() 0 22 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