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

SendToAddress::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 5
crap 1
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