Passed
Push — master ( 4d2f0d...e49568 )
by Nathan
02:16
created

SendToAddress   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 36
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
B jsonSerialize() 0 13 5
1
<?php
2
3
namespace ZenCash\Rpc\Command\Wallet;
4
5
use ZenCash\Rpc\Command;
6
7
final class SendToAddress implements Command
8
{
9
    private const METHOD = 'sendtoaddress';
10
    private $address;
11
    private $amount;
12
    private $comment;
13
    private $commentTo;
14
    private $subtractFromAmount;
15
16 4
    public function __construct(
17
        string $address,
18
        float $amount,
19
        ?string $comment,
20
        ?string $commentTo,
21
        bool $subtractFromAmount = false
22
    ) {
23 4
        $this->address = $address;
24 4
        $this->amount = $amount;
25 4
        $this->comment = $comment;
26 4
        $this->commentTo = $commentTo;
27 4
        $this->subtractFromAmount = $subtractFromAmount;
28 4
    }
29
30 4
    public function jsonSerialize(): object
31
    {
32
        return (object) [
33 4
            'jsonrpc' => Command::JSON_RPC_VERSION,
34
            'id'      => Command::ID,
35 4
            'method'  => self::METHOD,
36 4
            'params' => array_merge(
37
                [
38 4
                    $this->address, $this->amount
39
                ],
40 4
                !is_null($this->comment) ? [ $this->comment ] : [ ],
41 4
                !is_null($this->comment) && !is_null($this->commentTo) ? [ $this->commentTo ] : [ ],
42 4
                $this->subtractFromAmount !== false ? [ $this->subtractFromAmount ] : [ ]
43
            )
44
        ];
45
    }
46
}
47