Completed
Push — master ( abede7...d40790 )
by Nathan
02:18
created

SendToAddress::getSubtractFromAmountParam()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
eloc 1
nc 2
nop 0
crap 2
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
                $this->getCommentParam(),
41 4
                $this->getCommentToParam(),
42 4
                $this->getSubtractFromAmountParam()
43
            )
44
        ];
45
    }
46
47 4
    private function getCommentParam(): array
48
    {
49 4
        return !is_null($this->comment) ? [ $this->comment ] : [ ];
50
    }
51
52 4
    private function getCommentToParam(): array
53
    {
54 4
        return !is_null($this->comment) && !is_null($this->commentTo) ? [ $this->commentTo ] : [ ];
55
    }
56
57 4
    private function getSubtractFromAmountParam(): array
58
    {
59 4
        return $this->subtractFromAmount !== false ? [ $this->subtractFromAmount ] : [ ];
60
    }
61
}
62