Completed
Push — master ( 73e8d8...6dcceb )
by Nathan
02:35
created

SignRawTransaction::__construct()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.6666
cc 2
eloc 6
nc 1
nop 4
crap 2
1
<?php
2
3
namespace ZenCash\Rpc\Command\RawTransactions;
4
5
use ZenCash\Rpc\Command;
6
use ZenCash\Rpc\Command\RawTransactions\SignRawTransaction\SigHashType;
7
8
final class SignRawTransaction implements Command
9
{
10
    private const METHOD = 'signrawtransaction';
11
    private $hex;
12
    private $prevtxs;
13
    private $privateKeys;
14
    private $sigHashType;
15
16
    /**
17
     * @param string $hex
18
     * @param RawTransaction[] $prevtxs
19
     * @param string[] $privateKeys
20
     * @param null|SigHashType $sigHashType
21
     */
22
    public function __construct(string $hex, array $prevtxs, array $privateKeys, ?SigHashType $sigHashType)
23
    {
24
        call_user_func_array(function (RawTransaction ...$t) {}, $prevtxs);
0 ignored issues
show
Unused Code introduced by
The parameter $t is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

24
        call_user_func_array(function (/** @scrutinizer ignore-unused */ RawTransaction ...$t) {}, $prevtxs);

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
25
        call_user_func_array(function (string ...$keys) {}, $privateKeys);
0 ignored issues
show
Unused Code introduced by
The parameter $keys is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

25
        call_user_func_array(function (/** @scrutinizer ignore-unused */ string ...$keys) {}, $privateKeys);

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
26
27 4
        $this->hex = $hex;
28 4
        $this->prevtxs = $prevtxs;
29 4
        $this->privateKeys = $privateKeys;
30 4
        $this->sigHashType = $sigHashType ?: SigHashType::ALL();
31 4
    }
32
33 4
    public function jsonSerialize(): object
34
    {
35 4
        foreach ($this->prevtxs as $t) {
36 3
            if (!property_exists($t, 'scriptPubKey') || !property_exists($t, 'redeemScript')) {
37 3
                throw new \InvalidArgumentException("RawTransaction missing required data.");
38
            }
39
        }
40
41
        return (object) [
42 4
            'jsonrpc' => Command::JSON_RPC_VERSION,
43
            'id'      => Command::ID,
44 4
            'method'  => self::METHOD,
45 4
            'params' => array_merge(
46 4
                [ $this->hex ],
47 4
                !empty($this->prevtxs) ? [ $this->prevtxs ] : [ ],
48 4
                !empty($this->prevtxs) && !empty($this->privateKeys) ? [ $this->privateKeys ] : [ ],
49 4
                (!empty($this->prevtxs) && !empty($this->privateKeys)) ? [ $this->sigHashType ] : [ ]
50
            )
51
        ];
52
    }
53
}
54